|
|
|
|
|
by joshka
3808 days ago
|
|
A few people have mentioned Michael Feathers' book Working Effectively with Legacy code already, but I'll add my piece on this. The book describes legacy code as any code without tests. It then goes on to describe the "legacy software change algorithm" (google that for more articles that will help you.
Get targeted legacy code into test harness and cover with tests:
1. Identify change points for the target change or new code addition.
a. Find test points where the behavior of the code can be sensed.
b. Break dependencies (very carefully and often without sufficient tests) and get the targeted legacy code into a test harness.
c. Cover targeted legacy code with (characterization) unit tests
2. Add new functionality with Test Driven Development (TDD)
3. Refactor to remove duplication, clean up, etc. It really is worth reading this book as it covers almost exactly your question: "22. I Need To Change a Monster Method and I Can’t Write Tests for It." and various other relevant chapters. Answering your manager question with a standard consultant answer "It depends". Refactoring code is about setting yourself up for future development. You should always be refactoring your code after you confirm it works. Asking your manager whether you do it should take on the same amount of importance as asking whether you should wash your hands after visiting the restroom. That said, developers can often feel a sense of ownership of code and not wish change for various reason (usually familiarity with the current crap situation). |
|