Laurent Bossavit asks if developers have seen the following effects when rewriting code from scratch…
- Rewriting the code takes much less time than the first time around
- Rewriting the code is a lot easier than the first time around
- The rewritten code is better factored, more readable than that lost
I’ve seen all three of these results when I’ve rewritten code from scratch, either from necessity or choice. It depends somewhat on the unique character of the code. If it’s relatively mundane or routine code I see the effect less strongly than if it was somewhat complex code.
I agree with Laurent’s observation that “up front design” can have similar effects. I view a small amount of up front design as a mental rapid prototyping session before or even during coding. I can mentally work out several alternative approaches and decide how I want to proceed. However, I keep this pre-coding activity very minimal. I haven’t seen extensive up front design be a good ROI because it’s easy to overlook code-level issues.
Laurent also asks “what might happen if we made a systematic habit of throwing away our first attempt at coding any given chunk of functionality, and made a habit of only committing rewrites to CVS?”.
I probably wouldn’t rewrite software most of the time even if it would turn out marginally better the second time. If I’m reasonably happy with the existing implementation I’d prefer to keep developing new code. However, if I’m not happy with the existing implementation and I know a much better alternative I’d be probably rewrite it from scratch. I’d consider it from a cost/benefit perspective.