Friday, December 5, 2008

My best code review

In 1998 (or maybe 1999?) I was a fairly junior developer, but fortunate to be working under a really smart mentor (Aamod Sane).

Among many things that I'm grateful for was his relatively constant practice of helping me through constructive code reviews.

The one that sticks out, the one that changed my view of how to write my own code, started out with me excited with finishing the code and a few tests for some now forgotten task.

After reading through it myself to hopefully avoid really stupid mistakes ;) I kind of ran down the hall to get the attention of my supervisor/mentor.

Once he finished what he was doing we started walking back towards my workstation.

[...this is where it starts to get interesting...]


On the walk back towards my machine I was nervously and rapidly telling him what, why, and how the code does what it's supposed to.

[Me doing all this quick overview talking was important actually...]


We sit down at my machine, swivel the monitor over, and he start reading.

He....
sighs.



Then....
shakes his head.



Really. That's what happened.
Yes, you know what I felt like. ;)


If it had just ended there it would have been like any other awful code review (see http://www.osnews.com/story/19266/WTFs_m)



So, finally, the really good conclusion.

Before he left he said this to me:
Just make the code look like what you just told me.


That walk between machines earlier when I rambled my way through telling him what the code did was actually a fairly clear description of things. The code I had actually written was really detailed, messy, and all together just "code".


After the advice of my mentor, I looked at the code with fresh eyes and I could see better method names, better looping patterns, and just better ways to "tell the story" of what I was trying to do.


Now, I try to write my code so that it "reads" like a good story. Sometimes I do a really good job, and other times not so much, but I have a clear goal that I'm shooting for.

No comments: