Friday, June 01, 2007

The best code of all

I had been planning to write a short essay today on how I felt that I have just completed a few very productive days, where my net code output has been negative to the tune of a few hundred lines.  After all, this is something I have touched on previously, albeit in passing, but I felt needed a bit more emphasis.

And then, in a fit of synchronicity, Jeff Atwood blogs on essentially the same topic, albeit from a different direction -- The Best Code is No Code At All.

It may be something of an acquired taste, but one of the best experiences I find in software development is the point where you are able to delete code.  In project terms, being able to do so marks the point at which the metaphorical rough-cut timber is finally getting sanded down and polished.  Source control systems are there to remember how things were, for good or for ill; so code that is obsolete, or that there is a just plain simpler and plainer way to do, can get the chop with a clean conscience.

While exploratory phases of development may involve a measure of throwing code at a problem until enough of it sticks, and on the first time, cut-and-paste may seem the more attractive code-reuse strategy, coding smaller will pay dividends in the long run.

Just don't leave the flabby code there expressly to get the deleting-it-all kick later.

1 comment :

Anonymous said...

I too know the rather satisfying feeling that comes of being able to delete unwanted code, and the resulting clean solution structure that results (although it's often entertaining to see the look on a project managers face when you explain that you've spent the day deleting more code than you've actually written!)

However, I think there is a difference between keeping a design simple and the syntactic brevity that Jeff aludes to in his post. I'm all for the KISS approach to development, but also appreciate the readability (and inherent maintainability) of verbose code. Scrimping on such things as variable names is just lazy coding to me, and doesn't result in more efficient code - just code that is harder to read.