Monday, December 27, 2004

Developers Dilemma – Rewrite vs. rework

I’m just embarking on a new project today and looking through the existing code base. One of the components has some unit tests, which made me smile. None of the other components (about 8 in total) have any tests :(
This suite of components was written in a short time frame over a year ago and it works perfectly for the job that was required then. In fact it has been in use by (so I am told) several thousand users around the world for the last year. Of course there have been a few issues reported but no show stoppers. In many ways I have to say "good job" to the original development team.
The issue now is that the suite of components needs to extend its functionality further to cater for some technology changes and to open up new opportunities.
So the classic dilemma; do I rewrite the parts that need changing (in a test driven manner of course) OR do I rework the existing components and add tests as I go?
I don’t want to rewrite code that is working and has been field tested. I also don’t feel comfortable adding to code that doesn’t have unit tests. Without unit tests for the existing code I won’t know if I’ve broken any of the current functionality through the changes I am making.
To be continued …


Anonymous said...

Isn't that the whole point of refactoring rather then rewriting? :)
I thought you were the one who mentioned that if you have code you need to extend, but no tests, you write tests first and then extend the functionality.
And, besides, rewriting code that works is a silly job :)


Dr. Neil said...

Alex, I agree, I don't want to change code that works. Right now I am thinking I will have to write tests around all the existing functions. My fear is breaking existing functionality, the only way I can confirm that no existing functionality is broken is with tests.
Tomorrow I will start with one of the components. Stay tuned ...

Anonymous said...

I'd be interested to see how you fare in wrinting tests for the existing code. I'm expecting that you're going to find another delimma that leads you back to the question of rewrite vs. rework. Specifically, I would expect that you're going to find some measure of code that isn't built to be testable to begin with, and is subsequently less granular and atomic. I would also expect that becuase if the potential inability to write a small number of small tests for a number of fine-grained objects, that you're going to have to write a prodigious amount of test code to get complete coverage.

I hope you share your thoughts as you go along.