Where does 'legacy code' comes from?

Often people are scared to touch legacy system, and holding on tightly to the principle 'if it ain't broken don't fix it'. New features then is added around this huge mess of tangled webs of codes, which do nothing but contributing to more chaos.

So when does a good working code turned into 'legacy code' ?

It's important to have a common definition to the term 'legacy code' to stop it from being produced in the first place. Any code without test around it, that verifies how it should behave, is legacy code even it was 'only' 1 day old.


Creative Common: branditlessler

UPDATED 30 November 2008

Just a shout out on this post. I *think I* read about the idea from Gerard Meszaros's xUnit Test Patterns. It's interesting to listen to Michael Feathers advocating the same idea on Dot Net Rocks #397 Michael Feather talks legacy code. A good listen.

  1. says:

    I'd say code becomes legacy under 2 conditions:

    1) In the case where there isn't much documentation, it becomes legacy when it's authors leave the project.

    2) When you start using different technologies that may not be compatible.

    It is impossible to say not to write legacy code, even with a multitude of tests around it. Technology advances at a furious pace, so languages and methodologies fall out of use. One day were going to look back and think "hey, i remember writing OO code", but everything will be different.

    Eventually everything we write - unless we consistently update it - will become legacy.

  2. says:

    Legacy code is practically code that weren't written nor maintained by you previously, but handed over to you, hence the term 'legacy'. Documentation could exist or not. I think ... :)

  3. ronaldwidha says:

    To some extent, I agree with both of you.

    Author left the organization, no document, obselete technology leads to one fact: it's a nightmare for us to have to deal with this system.

    The lowest common denomination of all the factors seem to be: it all depends on whether a piece of code can still be maintained, patched and extend in a confident manner.

    Since, most factors are out of our control (you can't force someone to stick to one job....or can you??), the 'Tested code' definition seem to be a reasonable proposition to maintain the integrity of a piece of code.

    As long as Darwinism allow it to linger of course (-: