Monday, September 20, 2010

Explain It To A Newbie

As we work with code, we form habits. Some of them are great habits - run the tests before checkin, for example. Some habits are bad habits - writing only unit tests and no acceptance tests until after all the code is written, for example. Many habits are neutral habits - using rspec, for example. In all cases, they're ruts we fall into.

I'm suspicious of ruts. When I stay in a rut too long I worry that I'm not doing things as efficiently as I could. Maybe there's some newer methods that make things faster/better/stronger. Sometimes switching doesn't make sense, and sometimes it does. But you have to think about your habits to even consider changing them. It's shark engineering - keep up with the tools or you'll die!

To evaluate my habits, I'll grab a friend who's new to the codebase and explain what's going on.

For example, this is a recent one (a good habit):
Me: "Run bundle install to grab all the dependencies"
Him: "What is bundle install do?"
Me: "Bundler is a Rails 3 utility that allows you to specify all the gems your project depends on and just install them as you need them."
Him: "Oh, that's pretty cool. Saves discovering dependencies manually or installing them weirdly."

Or another recent one (neutral, this time):
Me: "Yup, we're using rspec here"
Him: "Why rspec?"
Me: "Well, it's in Rails core so there's not much to install, and the feature set is broad enough I haven't found much I can't do yet."
Him: "Oh, well, okay."

And a third (oops - a bad one):
Me: "I'm loading these with a rake task."
Him: "That's seed data, right? Why not use seeds.rb?"
Me: "Well, I taught the person providing the data how to write yaml so it's easy."
Him: "Sure, but seeds.rb can run any Ruby, so you can load the yaml from there, and then a new developer will be able to use the standard method."

This was a bad practice - and I fixed it. He was right, after all.

The point here is that I'm explaining my practices to a newbie - someone who doesn't know the code but who is an engineer. That innocent question - "Why?" - forces me to revisit a habit and to justify it. If it's good, the habit survives. If it's bad, the habit generally doesn't survive the explanation - and then I know to change it.

So if you're worried about habits, find someone and start explaining yourself - it's amazing what you can learn.

1 comment:

  1. Trying to avoid ruts is a good thing. Imo.

    Just like in real life, the longer you stay in a rut, the deeper it tends to get. The deeper the rut gets, the harder it becomes to see past the habit you've formed.

    If you just keep running in the same rut you're eventually going to make it so deep you won't be able to see over the edge at all anymore.

    That's when you're in trouble because then you lose the big picture and will need someone or something to give you a jolt, in order to realize what you've gotten yourself into so you can climb out of the rut and see the horizons again.

    Besides, realizing you've gotten yourself in a rut and climbing out every once in a while keeps you flexible. Be that physically or mentally, makes no difference - even if the flexibility is of different sort. :)