Michael Feathers
Working Effectively with Legacy Code
Michael Feathers on changing code you did not write and cannot yet test, by getting a safety net in place first.
The argument. Legacy code, in Feathers’ sense, is code without tests. To change it safely you first get it under test, using the smallest changes that make that possible, and only then make your real change. The book is a catalogue of ways to break the dependencies that stop a piece of code from being tested.
Ideas worth keeping
- The legacy dilemma. To change code safely you want tests, but to add tests you often must change the code.
- Seams. Places where behaviour can change without editing the code there.
- Characterisation tests. Record what the code does now, right or wrong, and keep it passing while you work.
- Sprout and wrap. Add new behaviour in a new, tested piece instead of weaving it into the old one.
- Cover and modify, not edit and pray.
Where it shows in Classroom Manager
When older parts of the program move to a newer design, we first write tests that record what they do today, including awkward partial-failure behaviour, and only then move them.
Who should read it
Anyone who maintains software that has outlived its authors, which is most software that matters.
Find the book (Open Library) ↗ (opens in a new tab)
Notice: the title, the author's name and any related marks, names and trade dress of the book discussed on this page are the property of their respective owners and are referred to for the purposes of identification, criticism and review only. Dausuva is not affiliated with, sponsored by or endorsed by the author or the publisher. The summary above is original text written by Dausuva, does not reproduce the book, and does not replace it. All rights in the book are reserved by their respective owners.