Re-writing code

Loads of Blogging springing from an article Rewrites Considered Harmful? – by Neil Gunton that goto posted to Slashdot, I saw it first at Blue Sky On Mars: Agility and rewriting code which pointed to the much better article by Joel on Software – Things You Should Never Do, Part I.

My own take is much the same, it is something that I too have seen more than once (and made the mistake myself at least once). Often we like to say it is because technology has changed, so we need to re-write in another language.

For me the most obvious case was an application I inherited written in DataFlex (an Object Orientated language with it’s own hierachical database). It included one source file with a mixture of OO and procedural code. Total length of this one file was 28,000 lines with 16,000 lines in a single procedure. It was critical to the whole application and nobody knew how it worked, there were no tests. It used global integers so extensively that the limits of the language had been reached, therefore many of them were being used for multiple purposes depending on the part of the program.

It looked like a disaster, there were no specs, there was no time and the original developer had left.

Yet, in less than a week I had a cleanly structured code base neatly divided into multiple packages with few global variables. It was hairy, but it is possible given a good working environment (silence, no interruptions, a good editor, version control system and sample data that you can run on the original and refactored code). The point is not to blow a trumpet but to give hope. The company had reached a point of paranoia about this code, it had the most bugs, the greatest number of extentions wanted and they did not dare touch it – but also could not afford the time for a re-write.

Now you would find it much harder to get me to accept a full re-write. In fact as I look back some of the most enjoyable coding excercies have been major refactorings – with the intention of taming code so that we could move on – many major jumps forward in projects came as a result of these exercises.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>