When do you say that the code is Legacy code?

孤街醉人 提交于 2019-12-10 14:13:59

问题


Any useful metrics will be fine


回答1:


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.




回答2:


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



回答3:


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.




回答4:


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




回答5:


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:


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.




回答7:


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.




回答8:


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.




回答9:


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"




回答10:


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.




回答11:


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.




回答12:


  • When the code is old enough you never met the developer who originally wrote the code.
  • When 3rd party libraries aren't supported anymore.



回答13:


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".




回答14:


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.




回答15:


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.



来源:https://stackoverflow.com/questions/119017/when-do-you-say-that-the-code-is-legacy-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!