Instant Legacy Code

Have you ever started a project knowing that you’re doing it wrong? When I first started coding up my MoneyJar application I knew that I would learn something further down the line that would make me want to start over.

Arguably, all projects start off one way and end up as something else. Does that mean all projects start off wrong? Anyway, I digress.

When I started writing the production code for the MoneyJar application I was in such a hurry to test out new ideas I decided to proceed without unit tests. Not knowing how to use them or how to write them I decided that it would slow me down too much, so I just didn’t do them. However, having now covered those topics, I realize now that that decision was wrong and now I have a lot of work on my plate to rectify the situation. What I had done, in effect, was write instant legacy code.

My first thoughts was to scrap it and start over. However, like many books on programming says you should use as much of what you have already done. More importantly it is exactly the sorted of thing refactoring was made for – taking badly written code and turning it into something clean, readable, maintainable, and of course testable.

Seeing what I had done, and the opportunity ahead of me, I decided to have a look at “Working Effectively With Legacy Code” by Micheal E. Feathers. In this context, legacy code is code that isn’t supported by tests. Which is exactly the situation I am faced with. This book is largely a book about refactoring and strategies to get legacy code into a test harness. It’s a bit wordy and sometimes difficult to read. But definitely a book at consider. After all, you could spend a lot of time working on legacy code. It could be good for the career, and my sanity when working on other projects.

While having read much about unit testing and test driven development, there is one thing that appears to be missing from these books. They tell you what good tests should look like and why you need them but there isn’t much detail on what heuristics you could use to choose or create these tests, as in how to come up with what and how to test code thoroughly.

Think it’s time for a bit of research and review.

Comments are closed.

Powered by WordPress. Designed by Woo Themes