Monday, October 25, 2010

Legacy Code Lesson - Part 1

Legacy code has been teaching me a lot of stuff. Reminding me how important tests are, and making me realize the advantages of doing TDD. So here I am on a task of re-factoring a piece of 'working' functionality. There are unanswered questions in my mind-
1. How do I know it is working? I do not see tests..!
(But hey there are integration tests somewhere..! Ohh I hate those.. :( Long runs..!)
2. What is that's exactly wrong with it?
3. Where do I start?

With these in mind, finally I started with of-course writing tests. Getting unit tests running itself, is a big step. The very first unit test fails, and I grin like a winner. But hey, it fails because some configuration somewhere is missing. I start noting down the things to correct..!

1. The code is completely coupled, too many dependencies
2. Constructor doing more than it should
3. Lot of helpers a.k.a static classes
4. Lot of Singleton mess
5. String, strings, strings!!
6. Enums and lot of them
7. Method with 10 parameters. :( aww..!

And I am tired and up for a coffee break already..! There are bigger decisions to be made, re-factor or rewrite?

1 comment:

  1. If code is already working on live environment then refactoring is better option.
    Top ones don’t care how it has been written if it’s working live :-)

    We go through the same every day. Only thing we can do is to welcome upcoming employees with the good documentation, which will save them time and frustration

    ReplyDelete