Tuesday, 31 July 2012

Code review(ed)

Today I had the rare, but pleasant experience of getting my code
reviewed by a colleague. We were talking about some aspects of Python at
lunch, and he volunteered to take a look at my code, so I said yes
please. Later in the afternoon he sat down with me, and we went through
almost 300 lines of my code and I learnt a couple of things. For one,
I'm not doing too badly (i.e. not too un-Pythonically), something I was
not at all sure about. For another, I was doing something quite ugly
with iterating over lists of tuples, where my reviewer pointed out I
could use a dictionary and get a much more elegant, readable &
maintainable result.

The point is that I learned stuff, and my code is now better.

Unfortunately, in this environment (an academic research institute) code
writing is still predominantly seen as a solo activity conducted as a
means to an end which does not need to be discussed. Only the results
need to be discussed.

The quality of code I see being written by doctoral students varies
greatly. Some is excellent, some less so. And I think it's a shame that
learning opportunities are being lost because hardly anyone reads
anybody else's code. It's not only the weaker coders who could gain in
terms of productivity during their PhDs, the better ones might happen to
find bugs sooner too, on the basis that two heads are better than one.
And in both cases, doing a bit of code review should stand them in good
stead for their future careers, in which they are very likely to
continue to write code, whether in academia or in industry.