How Many Times Should One Rewrite Code?

One should rewrite code for improved performance, structure and design. But how many times? In the beginning my thought was to possibly rewrite code twice. Later I found rewriting my own code three or four times made it better. This lead to very stable code and useful particularly as a library, API or framework. Now my belief is that to properly understand a problem and to produce really great code, it needs to be written half a dozen times to a dozen times!

I am sure a lot of people are laughing at the claim above, I assure you that I am not code challenged. Here’s what Charles H. Moore (Chuck Moore), inventor of the Forth Language has to say about rewrites:

Before you can write your own subroutine, you have to know how. This means, to be practical, that you have written it before; which makes it difficult to get started. But give it a try. After writing the same subroutine a dozen times on as many computers and languages, you’ll be pretty good at it. If you don’t plan to be programming that long, you won’t be interested in this book.

For more information please see: Programming a Problem-Oriented-Language by Charles H. Moore (

The more one writes the same code again and again, a few amazing things happen. The code structure gets better. Refactoring improves. Code quality goes up. And most importantly a pattern emerges leading to improved and solid design. The code becomes extremely elegant and beautiful. Highly satisfying to use.

For most commercial projects, rewriting so many times if at all, is course not financially possible. Too many times software gets written, becomes a success, but no one dare rewrite it because of the resource implication to undertake such a task. But if one was to write code for personal projects then nothing is more satisfying than to improve one’s work. It is important not to be afraid to begin from scratch.

Hope this theory does not lead to code obsession. A proof that code rewrite is important and necessary can be proven if you ask yourself a few questions, ask yourself:

  • Am I better programmer today than yesterday?
  • Could my code today be better than what I wrote before?

When I reflect back the answers are always true. So the code that I can write today will always be better. Hence the call for a rewrite!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s