What makes code legacy?

后端 未结 21 1995
说谎
说谎 2020-12-13 02:04

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 ma

21条回答
  •  一生所求
    2020-12-13 02:43

    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.

提交回复
热议问题