tags:

views:

784

answers:

17

I have heard many developers refer to code as "legacy". Most of the time it is code that has been written by someone who no longer works on the project. What is it that makes code, legacy code?

Update in response to: "Something handed down from an ancestor or a predecessor or from the past" http://www.thefreedictionary.com/legacy. Clearly you wanted to know something else. Could you clarify or expand your question? S.Lott

I am looking for the symptoms of legacy code that make it unusable or a nightmare to work with. When is it better to throw it away? It is my opinion that code should be thrown away more often and that reinventing the wheel is valuable part of development. The academic ideal of not reinventing the wheel is a nice one but it is not very practical.

On the other hand there is obviously legacy code worth keeping.

+14  A: 

What is it that makes code, legacy code?

As with plain legacy, when the author is dead or missing, you as a heir get all or some of his code.

You shed some tears and try to figure out what to do with all this rubbish.

Quassnoi
+14  A: 

By using hardware, software, APIs, languages, technologies or features that are either no longer supported or have been superceded, typically combined with little to no possibility of ever replacing that code, instead using it til it or the system dies.

cletus
+4  A: 

http://en.wikipedia.org/wiki/Legacy_code

"Legacy code is source code that relates to a no-longer supported or manufactured "

Sergio
...operating system or other computer technology"Interesting style of quotation you've got going there. :P. Who needs nouns after all.
RJFalconer
+6  A: 

Legacy code is source code that relates to a no-longer supported or manufactured operating system or other computer technology.

Galwegian
+10  A: 

Legacy generally refers to code that is no longer being developed - meaning that if you use it, you have to use it on its original terms - you cannot just edit it to support the way the world looks today. For example, legacy code has to run on hardware that may not exist today - or is no longer supported.

+4  A: 

Any code with support (or documentation) missing. Be it:

  • inline comments
  • technical documentation
  • spoken documentation (the person who wrote it)
  • unit tests documenting the workings of the code
Gerrie Schenck
+11  A: 

Michael Feathers has an interesting definition in his book Working Effectively with Legacy Code. According to him legacy code is code without automated tests.

Brian Rasmussen
What pie in the sky nonsense. Well, those who can, do, those who can't, teach (or coach software development teams).
cletus
If you think about legacy code as code which is hard to maintain, then the definition makes perfect sense imo.
Brian Rasmussen
Disagree: Code without automated tests == bad code (but can be targeted to modern, up to date systems, != legacy). Code with automated tests == better code, but if it is for Windows ME, it is definitely legacy.
Treb
Semantics. The point of Michael's definition is that if you write code that can't be easily changed, it's already legacy before you even finish. To write code that can be changed, you must have tests (at a minimum). There may be more to it, but the simplification is meant as a rhetorical device.
Adam Bellaire
It's possible to write code that's difficult to maintain in the most modern of languages. As much as I appreciate the value of automated tests, their absence alone does not constitute legacy code.
Scott A. Lawrence
@Adam Bellaire: well said.
Brian Rasmussen
@Adam: the idea that you can unit testing any piece of code is what I was referring to as "pie in the sky nonsense". Not all code is possible (or even practical) to unit test. Javascript engines and CSS layout spring to mind.
cletus
@Adam Bellaire: Michael wants to stress the importance of tests, and of course he does have a valid point. But as a definition for legacy its just bollocks. Semantics are the basis of a definition...
Treb
@Adam: Nicely summarized! "Legacy" in the sense of "crufty and painful to the touch" is a legitimate category, regardless of language or age.
joel.neely
+12  A: 

It is a very general (and oft abused term) but any of the following would be legitimate reasons to call an app legacy:

  1. The code base is based on a language/platform which is entirely unsupported by the manufacturer of the original product (often said manufacturer has gone out of business).

  2. (really 1a) The code base or platform on which it is built is so old that getting qualified or experienced developers for the system is both hard and expensive.

  3. The application supports some aspect of the business which is no longer actively grown and for which alterations are extremely rare, normally to fix it if something entirely unexpected changes around it (the canonical example being the Y2K issue) or if some regulation/external pressure forces it. Since both reasons are pressing and normally unavoidable but no significant development has occurred on the project it is likely that those people assigned to deal with this will be unfamiliar with the system (and it's accumulated behaviours and intricacies). In these cases this would often be reason to increase the perceived and planned for risk associated with the project.

  4. The system has/or is being replaced with another. As such the system may be used for much less than originally intended, or perhaps only as a means of viewing historical data.

ShuggyCoUk
+6  A: 

According to Michael Feathers, the author of the excellent Working Effectively with Legacy Code, legacy code is a code which has no tests. When there is no way to know what breaks when this code changes.

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.

hmemcpy
I guess by that definition jQuery is legacy code. It's what I'd expect from a "software development coach" or an academic.
cletus
The jQuery project has extensive unit tests. See http://docs.jquery.com/QUnitIMO, unit testing is not a universal standard yet, so it's unfair to call applications without them "legacy." I think in another 10 years or so this might be true.
davogones
+4  A: 

A colleague once told me that legacy code was any code that you hadn't written yourself.

Arguably, it's just a pejorative term for code that we don't like any more for whatever reason (typically because it's not cool or fashionable but it works).

The TDD brigade might suggest that any code without tests is legacy code.

Dan Dyer
A: 

Simplest definition: Legacy code is code which is not yet refactored.

pi
A: 

Code (or anything else, really) becomes "legacy" when it has been replaced by something newer/better, and yet despite this it's still used and kept alive "in the wild".

Wayne M
A: 

For me legacy code is code that was written prior to some paradigm shift. It may still be very much in use but it is in the process of being refactored to bring it into line.
e.g. Old procedural code hanging around in an otherwise OO system.

meouw
A: 

Quite honestly legacy code is any code, framework, api, of other software construct thta's not "cool" anymore. For example COBOL is unanimously regarded as legacy while APL is not. Now one can also make the case that COBOL is consideed legacy and APL not because it has about 1m times the install base as APL. However, if you say that you need to work on APL code the reply would not be "oh no, that legacy stuff" but rather "oh my god, guess you won't be doing anything for the next century" see the difference?

klyde
+1  A: 

Preserving legacy code is not so much an academic ideal as it is keeping code that works, no matter how poorly. In many conservative enterprise situations, that would be considered more practical than throwing it away and starting again from scratch. Better the devil you know...

Relic
It usually *is* more practical than throwing it away and starting from scratch.
MarkJ
A: 

I consider code "legacy" if any or all of the following conditions apply:

  • It was written using a language or methodology that is a generation behind current standards
  • The code is a complete mess with no planning or design behind it
  • It is written in outdated languages and in an outdated, non object-oriented style
  • It is difficult to find developers who know the language because it is so old

Unlike some of the other opinions here, I've seen plenty of modern applications that work decently without unit tests. Unit testing still has not caught on with everyone. Perhaps ten years from now the next generation of programmers will look at our current applications and consider them "legacy" for not containing unit tests, just as I consider non object-oriented applications to be legacy.

If few changes need to be made to a legacy codebase, it's better to simply leave it as-is and go with the flow. If the application needs drastic functionality changes, a GUI overhaul, and/or you can't find anyone who knows the programming language, it's time to throw away and start over. A word of warning, however: rewriting from scratch can be very time-consuming, and it's difficult to know if you've replicated all functionality. You'll probably want to have test cases and unit tests written for the legacy application and the new application.

davogones
A: 

Legacy code is anything written more than a month ago :-)

Roger Lipscombe