I've been involved in several projects where almost everybody screamed "we need to rewrite everything" and actually taken part in a few projects where software was rewritten from scratch. And a few times it actually turned out fine. Which made me think since there are so many voices saying a complete rewrite always is a bad idea (Uncle Bob, Joel, Chad). So I just spent a few minutes thinking about my own experience since I was under the impression I actually had experience of a successful rewrite. But everyone is saying that is impossible.

So the first rewrite I've experienced was a two man project where we wrote a prototype/proof-of-concept, threw it away and then wrote a first version. That version was never used by the end users and we pretty soon found out that we've made a major design flaw so we rewrote it a second time. That version finally made it to the end users. I consider this a successful rewrite but was it? I'm a firm believer that you should not reuse code written for prototypes. So that is not a complete rewrite. And rewriting the second time could be done in a week since we noted the design fault pretty early. And even then we reused some code so the rewrite was actually a really large refactoring now when I look at it in hindsight. So that turned out to not really be a rewrite after all... Doh!

But in 1999 I was involved in a project where we rewrote a system that was not Y2K compliant. But then we did not just rewrite to have the same functionality. The rewrite included lots of new features and completely changed how the users worked with the application. So we did not really rewrite the system. We built a complete new, much improved application that was not only Y2K compliant, it was a much more efficient and powerful application than before. So when I look at it in hindsight... It wasn't a rewrite. It was a green field project.

So after thinking about it I must agree with all three articles linked above. Rewriting your application from scratch just because the design/code is a mess is seldom the best choice you can make. In stead the safest bet is to clean up your code. And this means refactoring your code. In the end you might have refactored everything but don't start from scratch. But still if you plan to completely change the way an application works and add a bunch of new features, then you might benefit from starting from scratch. But don't cal lit a complete rewrite. Because it's not.