Working Effectively with Legacy Code

Michael Feathers (2004)
Review date: August, 2008 (Read in June 2008)

Chapters 1-3 are dedicated to explaining various reasons to change code, and the dilemma of legacy code, here defined as code without tests. A first glance at faking collaborations is thrown. In chapter four the seam model is explained, and several variants of seams are demonstrated. A seam is a place in the code where we can make changes without affecting it. This is the first theoretical contribution. Tools, those used for testing, are the topic of the next chapter, but this chapter is rather short.

Part two of the book is called "Changing software", and chapters therein explain how to use sprout methods and classes to minimize impact on existing code, and explanations of TDD and "programming by difference". Chapter 10 is the core of this part of the book, is called "I can't run this method in a test harness", and contains examples of difficulties that you may encounter when putting a method under test, and how to solve them. Numerous situations are discussed, and equally many solutions provided.

Next couple of chapters reason more or less about dependency graphs and ways of targeting testing. A technique called "characterization tests" is presented, and ways of dealing with code that is cluttered with API calls are discussed. Finally, there's a chapter on testing non-object-oriented code (because everything so far has been about Java and C++).

In chapters 20 and 21 we learn how to deal with too large classes and excessive code duplication. The tale of monster methods is told in chapter 22.

The third part of the book contains a catalog of refactorings that aid in attacking legacy code.


Wow! There's only one thing I regret about this book, and it's the fact that I haven't read it sooner, like five years ago. Unfortunately I had figured many things, that are discussed in this book, out for myself, but that's my loss. Whatever you do, read this one!

Through the examples the author shows much experience and understanding of the problems encountered in legacy code. When reading this book you'll nod in recognition and feel joy and relief that somebody understands the pain and misery in altering untested and untestable code written by [insert curse here].

While many authors of similar books run a "claim for fame" race by naming everything they write about so that they can come up with their own "patterns", the names in this book feel well chosen and non-intrusive. The author makes an attempt to make legacy code related techniques more formal by introducing concepts like seams, sprouts, and characterization tests (I haven't heard of them in other contexts) and succeeds in my opinion.

The chapters about difficulties in placing a class in a test harness, and especially the chapter on monster methods feel so painfully familiar, and make up a solid core in the middle of the book. I really loved them. They contain so many practical examples of evil-doing and cure. Another obvious plus is the presence of C++. I don't really think in C++, and examples of link and preprocessing seams really triggered an aha feeling. It's good that not everything is Java. The bigger the picture, the better. From one thing to another, I'm so happy that this book didn't contain the vanilla text on JUnit. Seen it too many times.

After having read the book I experienced one subtle downside. I came to the realization that everything in this book was about a very narrow topic, and if you got the essence of it, the rest followed and felt obvious. Nevertheless, it's a great book, a must read and a good investment in your competence. They don't come better than this.

Who should read this book

Java and C++ developers with a couple of years of experience can't do without this book. Since it captures so much knowledge on legacy code, testing and refactoring, it's a must!


  • 2015-09-29

    It's been almost one and a half year since I reviwed a book! I've been too absorbed by Writing my own. Anyway, I'm back with Jeff Patton's relatively...
  • 2014-01-04

    New category! Performance! Reviewed The Every Computer Performance Book. Check it out!
  • 2013-09-10

    Reviewed a book that' slightly less technical, but much more fun to read. It's I.T. Confidential.
  • 2013-08-13

    Reviewed yet another book on Visual Studio 2012 and TFS. I also created a "Microsoft" category and moved the other TFS book there from the "Tools"...
  • 2013-08-05

    Updated the FAQ. Included information about getting a book reviewed.