Book
Working Effectively with Legacy Code
Michael C. Feathers
Summary
Michael Feathers defines legacy code as code without tests, turning a vague complaint about inherited systems into a specific problem with a specific remedy. The difficulty he takes seriously is circular: you want tests before you change anything, but the code often cannot be tested until it is changed. The opening chapters build the tools for breaking that circle, above all the seam, a place where behavior can be substituted without editing the code there, plus ways to sense what code does and separate it from its dependencies. The bulk of the book is arranged by the question a developer arrives with, each chapter titled as the complaint itself: I cannot get this class into a test harness, I do not know what tests to write, I need to change a monster method and cannot write tests for it. A final chapter collects the dependency-breaking techniques. Examples are in Java, C++, and C#.
Target Readers
- Developers who have inherited a codebase with no tests and need to change it without a rewrite they will never be given time for
- Engineers stuck at the point where a class cannot be instantiated in a test at all, who need a technique rather than encouragement
- Teams who want a shared name for the moves they make when breaking dependencies, so the work can be discussed in review
Tags
Colophon
- Publisher
- Shoeisha
- ISBN
- 978-4798116839
- Published
- Jul 2009
- List price
- ¥4,620incl. taxMay differ from the actual selling price on Amazon
Get this book
* The link above is an advertisement via Amazon Associates.Related Books
Prerequisites
- Recommended
Refactoring
Improving the Design of Existing Code, 2nd Edition
Martin Fowler
Reason: Once safe refactoring moves are in hand, you take on the hardest case: legacy code without tests. You first find seams to break dependencies, cover them with tests as a safety net, and only then improve the structure.
Sources
- Related
Unit Testing Principles, Practices, and Patterns
Vladimir Khorikov
Reason: After grasping the principles of good tests, you apply them to legacy code that resists testing. You introduce seams to break dependencies and pin current behavior with characterization tests before changing it safely.
- Related
Head First Design Patterns
Building Extensible and Maintainable Object-Oriented Software
Eric Freeman, Elisabeth Robson
Reason: When you can read the structure of existing code through the lens of patterns, you can move on to building a safe foothold in untested legacy code—finding seams, covering them with tests, and improving the design from there.
Next Books
- Recommended
Kill It with Fire
Manage Aging Computer Systems (and Future Proof Modern Ones)
Marianne Bellotti
Reason: Working Effectively with Legacy Code covers the techniques for getting untested code under test by finding seams, and changing it safely. Kill It with Fire works at the level outside that: whether an aging system should be rebuilt at all, whether a migration will add value, and how to tell when a project is finished, argued through case studies. Read with the code-level techniques already in hand, its alternatives to a rewrite are easier to picture concretely.