Managing legacy code can be intimidating and difficult. Michael C. Feathers details how to get the most out of working with legacy code.
“To me, legacy code is simply code without tests.”
I'm Ken. My team maintains 5 million lines of C++ code, some of it 25 years old and touched by 35 different programmers.
I read Working Effectively with Legacy Code, and I heartily recommend it. It offered hundreds of nuggets; some I knew, some new to me.
The central theme of the book is that legacy code is not just code you didn't write, it's code that isn't associated with tests. The challenge to getting legacy code under control is to make it tested, sometimes refactoring, rearchitecting, restructuring.
What the book asks for, and what we do every day on our own codebase.
Yep — the building blocks for working effectively with legacy code are reading legacy code, thinking about legacy code, and writing down what you learn. For yourself. For future you. For others.
Once that is in hand, for any part of the legacy code, you proceed on with test writing, refactoring, restructuring and rearchitecting as needed. Here's the cool part: even if you don't write tests, understanding your legacy code before you touch it is really useful.
We wrote a tool. It's called Understand. As I read the book, I realized I'd spent the last two decades working on the key skill the book required.
In a bit of dog-food-eating karma, we use Understand to maintain Understand. Day in and day out, our engineers can't imagine using anything else. And because we maintain — that is, read and try to understand — our own legacy code with it, it's pretty darn good at it. You can try Understand for free on Windows, Mac and Linux. And you should.
Understand is aimed at reading, browsing, and understanding legacy code. Most IDEs are about generating code, code colorization, and some have debugger integration.
Understand, at first glance, looks like other IDEs. Code colorization. File browsing. Auto-completion. But under the hood — and via the power of click synching and information pushing — Understand optimizes reading and thinking about legacy code, knowing exactly what is connected to the code you are reading. It's for grinding down connection chains, learning, and then backing up to where you started to start on the next line.
We use it for virtual debugging: stepping through code thinking about it, then backing up and thinking more down other paths. That's how you understand legacy code. It's how you fix bugs. It's the start of all refactoring. It's the knowledge building process of doing safe maintenance of code. This is all based on our unique and hard to do Hyper-Xref technology.
As you learn about your legacy code, you can use annotations — like Word or Google Doc post-it notes — to document what you learn.
Along the way, as you explore, document the architecture from the bottom up as it is actually built, versus as intended. Share that with everyone, and get what they discovered too. That turns no architecture into shared, understood, and useful legacy code architecture. This is just the tip of the iceberg about what Understand does to help you think about your code. So download it, and give it a try today.
Our free trial enables all features that can be used on a sample code base.
Windows, Mac and Linux.