tags:

views:

312

answers:

15

Any useful metrics will be fine

+10  A: 

One of the things that I look for in a code is unit test. This will give the freedom to refactor it. So if the code does not have tests I consider it a legacy code.

Nazgul
A Pragmatic Programmer I see here.
phjr
+1  A: 

the term "legacy code" is subjective and is probably a loaded term. but in general I subscribe to the view that legacy code is one that is not unit-testable and as such is hard to refactor.

cruizer
+5  A: 

Micheal Feathers, Author of the excellent "Working Effectively with Legacy Code", defines it as any code that does not have tests.

Avdi
Hmm... so according to this, 40% of code being developed today is Legacy code???
AviD
Yes. According to Feathers, if it's written without unit tests, it becomes legacy code the minute it's written.
Brad Wilson
Oh come on! Yes, unit tests are important, but this definition is taking it too far. Legacy means outdated. Code without tests is not outdated, it's just a pain in the ****
Treb
Define "outdated".
Avdi
I have not read Feathers, but I can guess his reasoning: if you do not have unit tests, then you have no way of verifying that any changes to the code have not broken it, therefore you should not be changing it, therefore it is legacy.
ShellShock
A: 

I maybe wrong, but I don't think there is an established metric for this.

Usually a piece of code is deemed to be legacy, when it has seen at least 5-6 release cycles( maybe more ). More often than not, the Original Implementor is no longer around and the code is maintained through.

Maverique
A: 

I don't know of any real metrics that can be used to determine if something is "legacy code" or not, but anything older than just written could be considered legacy. Legacy code means different things to different people/organizations, so it really is somewhat subjective.

Scott Dorman
+8  A: 

If the code:

  1. has been replaced by newer code that implements the same or functionality or better
  2. is not being used by current systems
  3. is soon to be replaced by something else altogether
  4. has been archived for historic reasons
  5. when vendors stop supporting it
TheObserver
Isn't that what you'd call cruft.
Sam Hasler
+4  A: 

I don't believe there is a definitive answer, but I do believe that the likelihood that code is legacy code increases with the number of people who don't want to touch it and the likelihood that changing it will cause it to break.

Orion Adrian
A: 

Almost seconds after the devs leave the premises. :)

If...

there's no money in the bank for new features

you can't find anyone that admits working on the project that needs fixing

the source code to the project you own has gone MIA

...then you're working on legacy code.

stephbu
A: 
  • When the code is old enough you never met the developer who originally wrote the code.
  • When 3rd party libraries aren't supported anymore.
Pascal Paradis
+4  A: 

A better question would probably be what marks a piece of code as non legacy.

To me legacy means unchangeable. So as soon as you're no longer 'able' to change it it's legacy.

Whether that ability is removed by fixed requirements, fear of breakage, knowledge loss, or some other impact is largely irrelevant.

A related note is that I don't think I'd ever use the exact word legacy as it stirs up too many emotions to be useful.

+6  A: 

We use the term "legacy" to refer to any code, still in use, developed using technology we have ceased active development in.

It is code that we would rather rewrite using more recent tools than modify in its current state.

Prestaul
A: 

In my opinion all code that is written is legacy code. It might take some time before the original intent and all the decisions made about the code is forgotten but sooner or later you cannot imagine what they were thinking while writing it. You never write legacy code yourself, right?

Using unit tests or some measure like seconds since the developer has left the building do not really measure whether or not the code is legacy code. Legacy code may have a good set of unit tests and comments and it may have undergone a strict code review and other analysis. This doesn't mean that the code is still relevant for the program at hand. It just suggests that the code might be comparably well written. And if it is no longer relevant, the code will actually make it harder to solve the problem the program is developed for.

Aleksi
A: 

Usually people refer to something as legacy code when no one is still around that is familiar with or feels comfortable maintaining the code.

Unit tests make it easier for people unfamiliar with code to dig into it, so the theory is it helps prevent code from becoming "legacy".

jwanagel
A: 

Often when code is legacy it is changed in a different manner. People are afraid to change it, but also changes tend to be quick and dirty because nobody understands full consequences. Code duplication issues may arise, because people don't want to take the risk associated with deeper changes.

So, in such circumstances, the situation may get worse, at an increasing rate.

phjr
+1  A: 

Legacy code has been defined in many places as "code without tests". I don't think they are specific in the types of tests, but in general, if you can't make a change to your code without the fear of something unknown happening, well, it quickly devolves.

See "Working Effectively with Legacy Code"

casademora