Agile software development using Kanban & Scrum. We code Flex & Ruby on Rails in Auckland, New Zealand.

  • Community support and IRC (introducing SQLRecord)

    A lot of my life has been spent on IRC. I got really sick of it. I got tired of the assumptions made by people meeting “anonymous” people for the first time. I include myself here, it seemed inevitable that I’d jump to conclusions without hearing someone out, and in turn made them sick of IRC too.

    However, in a recent expedition into making my first clean-coded, well thought out Ruby Gem, I turned to IRC for help.

    What I got was much more than I asked for, and it was all awesome-sauce.

    The Idea

    We use ActiveRecord::Base.connection.execute occasionally to run really fast read-only queries. Mostly for Dataviz.

    I don’t like it. You get a row of string-keyed string-valued hashes back from the database. All that knowledge about the schema and how to handle differently typed columns that ActiveRecord gives us, gone.

    Our views and view-helpers were littered with new idioms (bad habbits?) - the “Dealing with direct sql results” idioms.

    Not only that, but the SQL queries were in controllers! Ick.

    Enter SQLRecord

    My first cut of this gem is SQLRecord v 0.1.0

    It was my first ever DSL in Ruby, and I thought, quite idiomattic.

    Time to doc.

    So I started documenting. It was annoying me that my Yard Index was showing a module ClassMethods rather than showing them as Class Methods of the module that used the include-to-extend idiom.

    So I went to #yard at irc.freenode.net channel to ask about indicating that this module’s methods belonged to another. Loren Segal was there and told me there wasn’t any way of munging the docs…

    Extending themselves to the community.

    Here’s the beginning of that discussion:

    [08:50] Is there a trick in yard to make Module docs (like ClassMethods) look like those of the parent Module?
    [08:51] <@lsegal> you mean like get ClassMethods to be interpreted as a set of class methods? Unfortunately not really
    [08:52] yah thats what i meant
    [08:53] http://yehudakatz.com/2009/11/12/better-ruby-idioms/ I’m going to re-read this until i get it.
    [08:54] <@lsegal> indeed, that’s a good one. I’m not too fond of ClassMethods either
    [08:55] <@lsegal> poor docs being one reason why
    [08:56] <@lsegal> ClassMethods usually translates to “i have a poorly named mixin”

    Yehuda’s post was haunting me but I wasn’t understanding it.

    For the next 2 hours, off and on, Loren gave me a code review that changed my world view.

    I would say that he improved Ruby by improving one passionate developers view of Ruby.

    I now believed that good OO Principles were entirely practicable within this magical wonderland language called Ruby, where all ropes are long and could hang you, your family, and your-pit bull, without breaking a sweat.

    Now I had a new perspective, a better Gem and I was pretty sure I was coding what I needed, without over-cooking it.

    But wait, there’s more!

    So one thing that happened as I re-factored, was a mistaken version bump into the 1.0s. Not where I meant to be. I trotted off to #rubygems at irc.freenode.net.

    I got an answer about using gem ‘yank’ to remove a gem but then:

    <@drbrain> you should not be embarrassed by releasing early and often

    Ok then. I broke semantic versioning but I was hitting it hard and “showing my working”. Math education really does have value!

    A little later, out of the blue, and not related to my versioning problem, but the code itself, someone said:

    doesn’t AR::Base.find_by_sql solve this?

    Ok! Here we go, the IRC I know and hate. Someones about to tell me I’m doing it wrong without background information…

    Well no not really. Erik Hollensbe, as it turns out, had an abiding interest in what I was doing and made me argue the approach I was using. Moar gravy for my awesome-sauce.

    That’s it. Thankyou to the community for being open minded, passionate and brilliant. I’ve had a very good week.