chapter seven

7 Taming legacy code

 

This chapter covers

  • Reading unfamiliar code as active investigation
  • Mapping code smells to TIMWOODS
  • Applying YAGNI as a pull-based design principle
  • Strangling legacy systems incrementally
  • Using characterization tests and seams
  • Evaluating technical debt

Here's the uncomfortable truth: you're staring at a codebase you've never seen before. A change that should take an hour will consume your entire week. The code works; that's actually the problem. Nobody knows exactly why it works, and everyone's terrified to touch it. Sound familiar?

Legacy code isn't old code or bad code. It's code without sufficient safety to change confidently. That production payment processor from last month? It’s already legacy if nobody can modify it without sweating. The beautifully architected microservice from 2019? Legacy. The authentication system everyone depends on? Definitely legacy. Age has nothing to do with it. Safety does.

7.1 Understanding legacy code through a Lean lens

7.1.1 Two traps

7.2 Identifying and prioritizing waste in legacy code

7.2.1 Prioritizing waste by impact

7.3 Lean design principles for legacy code

7.3.1 YAGNI as a Lean design principle

7.3.2 Lean perspective on design patterns

7.4 Attacking a legacy codebase systematically

7.4.1 Technical debt

7.5 Exercise: Tame one legacy module this release

7.6 Summary