Two rather different angles on legacy code.
The first comes from Bjarne Stroustrup’s home page:
“Legacy code” is a term often used derogatorily to characterize code that is written in a language or style that (1) the speaker/writer consider outdated and/or (2) is competing with something sold/promoted by the speaker/writer. “Legacy code” often differs from its suggested alternative by actually working and scaling.
And the second comes from Michael Feather’s paper, “Working Effectively With Legacy Code”, which I guess forms the root of the book of the same name:
The main thing that distinguishes legacy code from non-legacy code is tests, or rather a lack of tests.
These very different angles aren’t mutually exclusive. You could have code without tests which works — and which even scales, I suppose. On the other hand, I’d hesitate to change code which works but which doesn’t have any tests, and I’d be even more reluctant to scale up such code.
What I particularly like about Feathers’ definition is that it’s objective — in the same way that the Turing Test is objective. Rather than getting sucked into emotive arguments about whether machines can think, Turing devised a practical experiment to determine a machine’s ability to appear sentient. Similarly, Feathers’ metric is easy to apply.
If you’re not convinced, here’s the paragraph in full.
The main thing that distinguishes legacy code from non-legacy code is tests, or rather a lack of tests. We can get a sense of this with a little thought experiment: how easy would it be to modify your code base if it could bite back, if it could tell you when you made a mistake? It would be pretty easy, wouldn’t it? Most of the fear involved in making changes to large code bases is fear of introducing subtle bugs; fear of changing things inadvertently. With tests, you can make things better with impunity. To me, the difference is so critical, it overwhelms any other distinction. With tests, you can make things better. Without them, you just don’t know whether things are getting better or worse.