Working Effectively with Legacy Code book
How to add tests, refactor, and add features to code that wasn't written with any of those in mind.
How to add tests, refactor, and add features to code that wasn't written with any of those in mind.
why it matters
Most engineers spend most of their careers in legacy code, but most engineering books pretend you start from green-field. Feathers wrote the book on the actual situation: a million-line codebase with no tests and a feature deadline. The 'seam' concept alone is worth the cover price.
key ideas
- A 'seam' is any place you can change behavior without editing the surrounding code (DI, virtual functions, link-time substitution). Finding seams is how you make untested code testable.
- Characterization tests: pin down current behavior (including bugs) before refactoring, so changes that break it are detected
- Sprout method: when adding to legacy, write the new behavior in a new method (testable, reviewable) and call it from a small site in the legacy
- The legacy code algorithm: identify change points, find test points, break dependencies, write tests, make changes — refactor
- Edit and pray vs cover and modify
who should read it
Anyone working on legacy code (i.e. most of us). Required for IC engineers shipping into long-lived systems.