Saturday, May 21, 2011

Say what you mean!

5 years ago I wrote my first line of Ruby. It was at a coding dojo while pairing with Corey Haines. At the time I was deep into the world of .NET and C# and had not yet seen a line of Ruby code. So when it came time for me to take the keyboard and make something happen I didn't have a clue where to start. That's when Corey said, "Just write it how you think it should be written". So I did. And what I had written while not exact Ruby syntax, was pretty close!

"But Corey, what about testing in Ruby?", I said. Corey then introduced me to the most important Gem in all of Ruby (insert drumroll here) ... RSpec. I was already an avid TDDer in C# using NUnit, so testing code was very familiar to me. However, NUnit always seemed lacking. No matter how expressive I tried to make the tests they never seemed to convey thoughts as clearly as I'd like. RSpec was not like that at all! Within minutes of pairing with Corey writing specifications in RSpec, I realized I had found my soul mate in RSpec! It was awesome!! I was able to Say What I Meant in code without any ceremony.

Yukihiro Matsumoto said "Code is an expression of the thoughts, attitudes, and ideas of the programmer." When it comes to expression of thought, Ruby is definitely an enabler!

Regardless of what language you are using to build your next application for world domination, pay attention to how you convey your thoughts in your code. Because without attention to how you organize your code, it can be very easy to get lost in the code and take a wrong turn. And the next thing you know you are pointing your Mega Laser at the wrong place during runtime!! (Hopefully your tests covered pointing the laser and saved your arse)

Avdi Grimm takes expression to the next level, emphasizing that developers should confidently express themselves in their code. The first step in building confidence and clarity in your code is to establish a consistent narrative structure. Avdi's proposed narrative structure is this:

  1. Gather Input
  2. Perform Work
  3. Deliver Results
  4. Handle Failure

Now that you are armed with this narrative approach to writing your code, don't forget to just simply Say What you Mean! Your co-workers will thank you in the end.