5

Any useful metrics will be fine

davr
  • 18,877
  • 17
  • 76
  • 99
Nazgul
  • 1,974
  • 4
  • 22
  • 34

15 Answers15

12

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
  • 1,974
  • 4
  • 22
  • 34
9

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
  • 2,973
  • 7
  • 33
  • 41
7

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
  • 83,552
  • 10
  • 84
  • 84
6

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

Avdi
  • 18,340
  • 6
  • 53
  • 62
  • Yes. According to Feathers, if it's written without unit tests, it becomes legacy code the minute it's written. – Brad Wilson Sep 23 '08 at 06:21
  • 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 Feb 24 '09 at 09:10
  • 1
    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. – Polyfun Mar 19 '10 at 10:43
  • I'm late, but some languages enforce 'code contracts' which make some aspects of unit testing obsolete. – James Jun 20 '12 at 13:31
6

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.

4

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
  • 19,053
  • 13
  • 51
  • 67
1

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
  • 6,103
  • 2
  • 27
  • 34
1
  • 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,275
  • 5
  • 37
  • 50
1

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 Yrttiaho
  • 8,266
  • 29
  • 36
  • I myself prefer this approach. Once code has been written, it is "legacy" whether there are tests that cover the code or not. You can have tests that cover code which was written aeons ago, no one is around that is familiar with the code, and/or using "old" technology... – Justin Greywolf Jan 04 '18 at 19:57
1

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
  • 67,775
  • 17
  • 69
  • 78
0

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
  • 73
  • 5
0

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
  • 5,072
  • 26
  • 42
0

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
  • 4,078
  • 1
  • 25
  • 33
0

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.

Paweł Hajdan
  • 18,074
  • 9
  • 49
  • 65
-1

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
  • 42,236
  • 12
  • 79
  • 110