What is legacy code? Is it code without tests?

  • The definition of legacy code as code without tests comes from Michael Feathers’ Working Effectively with Legacy Code.
  • An alternative definition is valuable code that is difficult to change (you are afraid you might break existing behavior) because you struggle to understand it.
  • You overestimate the complexity of unfamiliar code or code you don’t remember why you wrote. Sometimes it gets better after working with it a few months.
  • Having tests is not enough, good tests make you confident about changing unfamiliar code but poor tests don’t.
  • A recipe for legacy code is multiple people working on a codebase, over a long period, with conflicting requirements, under time pressure. This happens because knowledge is always imperfect and you take shortcuts to meet deadlines until every move introduces a bug and new features take ages to implement.
  • Finally, ‘legacy code’ is a matter of personal perspective: it depends on your understanding of the code and your feelings about changing it.

Full post here, 4 mins read