Book Review: Working Effectively With Legacy Code

This is a very important book on a topic that hasn't been covered thoroughly prior to its release.  For all the text out there about Agile software development, XP programming practices, unit testing, etc., there seems to be an unwritten understanding that you're dealing with a fresh, new project space.  And for me, specifically, that was the case for the past few years.  As a independent contractor, I was often brought in to projects at their beginning to see them through to completion.  But having recently re-joined the full-time employee ranks to maintain and improve an existing product, I now understand how overwhelming it can be to look at a giant codebase and think to yourself "ok, where do I even start?"

That's where this book comes in.

First, it's definition of legacy code is simple.  Any piece of code that is not under test.  I think that's a good starting point.  Too many people think of legacy code as having to have been written years ago and allowed to degrade.  Not true.  By the author's definition, legacy code is still being written by developers every single day.

So obviously, the point of the book is refactoring existing code to make it testable.  And what's provided are chapters describing different situations, such as "I'm Changing The Same Code All Over The Place" and "I Can't Run This Method In A Test Harness".  In that way, the book can act like a reference material for programmers working in legacy code.  If you see yourself running up against one of these problems, simply flip to the chapter list, find your problem and read the chapter about it.  Most chapters are pretty short and get right to the point.

After the situational chapters, the book ends with a list of refactoring techniques, written step-by-step, that you can apply to get pieces of your code under test.  It's very much like Fowler's Refactoring book, except with some new techniques explicitly for getting your code into a test harness.

I had heard that this book was useful for years now, but never bothered to pick it up.  But now facing a codebase that seems unwieldy, I think this may be one of the most important books I've ever read.  We don't all code in green pastures, but this book certainly helps you not lose focus of the techniques you hold dear (unit testing, separation of concerns, D-R-Y, single responsibility, etc.) when you encounter a situation that seems overwhelming.

http://www.amazon.com/Working-Effectively-Legacy-Robert-Martin/dp/0131177052