Stop Patching And Start Rewriting

I bet you know "Back to the Future", the famous movie trilogy by Robert Zemeckis. It's the story of the time travels of the young Marty Mc Fly, played by Erich Stoltz, and... wait! Erich Stoltz? I know what you are thinking: "No, it was Michael J. Fox!". And you're right. That is what we all have seen on the screen.

But when Zemeckis started filming, Michael J. Fox was not available, so, for five weeks, Erich Stoltz was the hero of Back to the Future. But Zemeckis was not satisfied. Stoltz hadn't the characteristics he was looking for. So he went to the producer (Steven Spielberg) and asked his permission to change the lead actor and throw away more than one month of work. Spielberg said yes (and provided some more money) and today we can say that he made the right choice.

Back to the Code

Now I guess you are thinking: "what is the relation between this story and programming?" Thank you for the question. Let me answer with a couple of questions: how many times have you thought that it would be easier to totally rewrite a piece of code instead of modifying it to include new features or to fix a bug? And how many times did you eventually rewrite it?

My answers are respectively "too many" and "too few". But the problem is not that many times I've had the temptation to throw away weeks of work. You know, when you start writing a non-trivial program, it's impossible to know all cases and anticipate all the future developments and avoid every bug. Moreover, as the time goes by, you learn new techniques and change your mind about what is considered good programming. So it's absolutely normal to look at some code you have written three or four years ago and feel the need of changing it.

The problem is when you leave the structure untouched. There can be many reasons for these but usually the time is the main. And for your boss, "time" means "money". But what your boss pretends to ignore is that a software continuously patched will be less performing and less error-proof. And probably there will be the need to change it again in few time.

Conclusions

I'm not saying that you should rewrite your code at every modification. Instead you should spend some time to design the software to be easily extensible. My point is: when you modify a piece of code always ask yourself if it would be better to rewrite it. And, if the answer is yes, go to your boss and tell him about Erich Stoltz.


Cover image taken from Wikimedia Commons (public domain)

Luca Sommacal

Luca Sommacal

Italian developer (mainly in C for embedded platforms), Linux learner, addicted to rock music, history, science and few other things. Follow me on Twitter

comments powered by Disqus