dagblog.
← Archive

Shake before prescribing


How many times have I been through this? Once, twice, three times? I honestly don’t know, but it’s been countless times. You don’t know what I mean? That’s all right. I’m sure you’ve been in this situation if you think back a little. You come across a piece of code and feel an irresistible urge to rewrite it from scratch. You don’t really have any serious reasons beyond declaring it a useless piece of crap that the hack before you made a mess of. It’s a compulsion euphemistically known as an occupational disease. You’re programmers, after all. You have to build things, preferably on a greenfield site.

So next time the urge hits, read Joel Spolsky’s article Things You Should Never Do, Part I, which was published eight years ago but is timeless (and I’m asking my colleagues to send me that link next time it hits me).

There’s a subtle reason that programmers always want to throw away the code and start over. The reason is that they think the old code is a mess. And here is the interesting observation: they are probably wrong. The reason that they think the old code is a mess is because of a cardinal, fundamental law of programming:
It’s harder to read code than to write it.
…When you throw away code and start from scratch, you are throwing away all that knowledge. All those collected bug fixes. Years of programming work.

I really recommend reading the article. So what options do we have besides rewriting everything? 
 
 I’ll turn to another article, 3 Options for Rebuilding Your Software Without Risking Death. In brief, the three options are:

  • Prototype and expand
  • Incremental
  • Buy

Which do you prefer? Having seen a few prototypes put into production, much to their developers’ displeasure, I instinctively lean toward incremental replacement.

In the incremental approach, you replace big components of your software with more modern components, or you refactor the existing code. However, you do this in a series of steps that leave you with a releasable and saleable product after each step. This is often compared to “rebuilding the plane in the air”.

In closing, there are cases where a complete rewrite is the best solution. If you do rewrite, keep it in proportion …

Medium version

Related articles

Related CZ Podcast episodes