Working Effectively With Legacy Code by Michael C Feathers
This is a really interesting book, which essentially talks about how to use more modern techniques, such as unit testing and refactoring, in a code base that wasn’t written that way, which the author terms legacy code.
The book has several sections. Part one covers the mechanics of change and was a fantastic read. It looks at the kinds of tooling that might be useful for working with such code, but for me the key ideas were sensing, separation and seams. Sensing is mocking plus the possible introduction of extra code and fields which allow a test to determine that something happened. Separation is the idea of being able to take some code and run it in a test harness, potentially faking or mocking the environment in which it usually runs. Seams are the places where you can introduce new code, perhaps by intercepting a method call and making it do something else in a test.
Part two of the book is a series of short chapters that focus on particular problems and their solutions – for example, “I don’t have much time and I need to change it”. The chapters are full of good practical advice, but whereas I found it easy to sit down and read part one, I found it really hard to go through each of these individual recipes and absorb them. I presume they would be better read when you have a problem of the particular type to work on.
Part three covers some dependency breaking techniques and was also really interesting.
In summary, I thought this was a good book, though some parts of it are not really suitable as a sit down and read the whole book. Some neat ideas.