“Working Effectively With Legacy Code” by Michael C. Feathers starts off with a bang, and probably the best and shortest definition of legacy code: “Legacy code is simply code without tests.” I couldn’t agree more.
The book is for all of us who have to deal with all kinds of code that is tangled, caught in a web of endless dependencies, or methods and classes that are simply too long, and/or do too much. Of course, said code usually comes along without unit tests. Now there you are, having to add a new feature or fix a bug. Where do you start? What’s that scary piece code over there doing? Why is it staring at you?
That’s where this book comes in. It’s split into three parts. The first will give a general introduction to the subject, introducing the mechanics of change, the need for testing, the seam model and the tools you need.
The second part is where the dirt is thrown right at you. In a style of “I need to do this” or “How can I do that?”, this part will shock you to your very core. No, probably not, but it will give you a lot of good advise on how to deal with a particular legacy-type situation. This part is where the book really shines. The examples given might be simple sometimes compared to real-world legacy code, but they give you a very good idea how to handle a particular situation.
In the last part Michael lists techniques for breaking dependencies. I’m not sure if I’d recommend reading these before the second part, but you should be aware that all of these techniques are regularly referenced in the first parts of the book. So be prepared to skim to this part if you need to know what a particular technique is about.
Consider “Working Effectively With Legacy Code” a companion to “Refactoring” by Martin Fowler. And while Fowler’s book taught you all about refactoring and the things you can do with it, this book will teach you how to put these things into practice, how to get code untangled, so that you can finally write tests for it, and add those new features.
This book will not solve all your problems, but it will give you an excellent head start, and guide you through the process of handling legacy code. I found this book to be of great value, and I couldn’t believe it took me so long to finally read it. Michael Feathers’ writing style is most excellent and thankfully, entertaining. Even if you’re not having the pleasure of working with legacy code right now, the time will come. You’ll be glad to have this book on your side.