Never, never rewrite whole code from scratch

Netscape failed because it rewrote its code from scratch

We’re programmers. Programmers are, in their hearts, architects, and the first thing they want to do when they get to a site is to bulldoze the place flat and build something grand. We’re not excited by incremental renovation: tinkering, improving, planting flower beds.

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.

This is why code reuse is so hard. This is why everybody on your team has a different function they like to use for splitting strings into arrays of strings. They write their own function because it’s easier and more fun than figuring out how the old function works.

The idea that new code is better than old is patently absurd. Old code has been used. It has been testedLots of bugs have been found, and they’ve been fixed. There’s nothing wrong with it. It doesn’t acquire bugs just by sitting around on your hard drive.

Each of these bugs took weeks of real-world usage before they were found.  If it’s like a lot of bugs, the fix might be one line of code, or it might even be a couple of characters, but a lot of work and time went into those two characters.

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.

You are wasting an outlandish amount of money writing code that already exists.

It’s important to remember that when you start from scratch there is absolutely no reason to believe that you are going to do a better job than you did the first time. First of all, you probably don’t even have the same programming team that worked on version one, so you don’t actually have “more experience”. You’re just going to make most of the old mistakes again, and introduce some new problems that weren’t in the original version.

24 years ago, Joel Spolsky (Joel on Software) wrote that rewriting software from scratch is the single worst strategic mistake a company can make. Does this take hold up today?

It overlooks an essential point: a lot of times the old code IS a mess. Sometimes because it was written poorly and hastily, but just as often it was because it took several years for the team to understand the problem and its solution. The process of learning what the true requirements are always takes time and iteration.

It’s worth doing in exactly one situation: when it becomes so hard to change the code that you can no longer maintain it. 

I think that’s true for everything in life. The first 80% takes 20% of the time and then the rest takes 80% of the time.