On code quality: rewrite once (blog.tetrack.com)
All you have to do is delete your first implementation and rewrite all the code from scratch. The main reason for this is that you can focus on code quality without being constrained by the existing implementation.
13 comments
[ 5.6 ms ] story [ 37.7 ms ] threadAt the moment, I'm working interfacing a handheld device with a networking device. I quickly wrote a prototype to work out implementation details (since connectivity required using a particular protocol). That's not to say I didn't write parts of the prototype to be refactored or pulled out, but given that I had to do a fair amount of exploratory programming to determine the best implementation, much of the prototype code will be thrown away.
So yes, its best to try to write it correctly the first time, but its ok to rewrite it a second. After that, you should probably look as to what you're doing wrong.
For example the library Powerplant (Metrowerks' mac equivalent to MFC) was rewritten a dozen times before it was released, as its design patterns needed a lot of fishing out to get them right.
I kind of have a vague feeling for why this would be true, but I can't quite put it into words. Maybe it has to do with how much structural stuff I have to write, or how directly I can express my program in the first place. Thoughts?
OK to rewrite the really bad stuff that has a high density of bugs. OK to adapt your architecture if it really doesn't fit the problem domain you are discovering and you really can make it simpler. OK to clean up basically ugly code that neither you nor others can easily understand. The important thing is to have a good reason to rewrite besides "I always do it that way."
Always rewrite from scratch on principle? This is the path to madness, failure, project overruns, and downright disasters. That is unless you are very very lucky. Luck helps but good software is not produced by luck.
So the suggestion isn't "the path to madness". The way to avoid the Second System Effect is simply to make a commitment not to develop new features on the rewrite. This second system will do the same as the first one except the code will be better.
An example of a successful project that did this is Subversion they pretty clearly said that they wanted to Create a CVS equivalent with certain annoyances corrected. That clear purpose and definition helped them avoid feature creep.
In any case, the solution proposed was not to avoid ever designing a second system, but to be mindful of this danger while doing so.
(Not that I'll follow this advice either. Deliberately forcing myself to solve the same problem the same way more than once would drive me nuts.)