是什么导致了代码遗留?

发布于 2024-07-12 04:18:28 字数 415 浏览 7 评论 0原文

我听说许多开发人员将代码称为“遗留”。 大多数时候,它是由不再参与该项目的人编写的代码。 是什么构成了代码、遗留代码?

更新响应: “从祖先、前辈或过去传下来的东西” http://www.thefreedictionary.com/legacy< /a>. 显然你想知道别的事情。 您能澄清或扩展您的问题吗? S.Lott

我正在寻找遗留代码的症状,这些症状使其无法使用或使用起来成为噩梦。 什么时候扔掉比较好? 我认为应该更频繁地丢弃代码,而重新发明轮子是开发中有价值的部分。 不重新发明轮子的学术理想是美好的,但不太实用。

另一方面,显然有一些遗留代码值得保留。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(21

背叛残局 2024-07-19 04:18:28

通过使用不再受支持或已被取代的硬件、软件、API、语言、技术或功能,通常几乎不可能替换该代码,而是使用它直到它或系统崩溃。

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.

假装爱人 2024-07-19 04:18:28

是什么构成了代码,遗留代码?

与普通遗产一样,当作者去世或失踪时,您作为继承人将获得他的全部或部分代码。

你流下了眼泪,并试图弄清楚如何处理这些垃圾。

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.

哀由 2024-07-19 04:18:28

Michael Feathers 在他的《有效处理遗留代码》一书中有一个有趣的定义。 根据他的说法,遗留代码是没有自动化测试的代码。

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

眼泪淡了忧伤 2024-07-19 04:18:28

这是一个非常笼统的(并且经常被滥用的术语),但以下任何一个都是调用应用程序遗产的合法理由:

  1. 代码库基于原始产品制造商完全不支持的语言/平台(通常说制造商已经停业)。

  2. (真的 1a)构建它的代码库或平台太旧了,以至于为该系统找到合格或有经验的开发人员既困难又昂贵。

    (真的 1a

  3. 该应用程序支持业务的某些方面,这些方面不再活跃增长,并且更改极为罕见,通常是在发生完全意外的变化(典型的例子是千年虫问题)或某些法规/外部压力迫使它。 由于这两个原因都很紧迫并且通常是不可避免的,但该项目尚未发生重大进展,因此分配处理此问题的人员可能会不熟悉该系统(以及它累积的行为和复杂性)。 在这些情况下,这通常是增加与项目相关的感知和计划风险的原因。

  4. 系统已/或正在被另一个系统替换。 因此,该系统的用途可能比最初预期的要少得多,或者可能仅作为查看历史数据的一种手段。

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.

ぺ禁宫浮华殁 2024-07-19 04:18:28

遗留通常是指不再开发的代码 - 这意味着如果你使用它,你必须按其原始条款使用它 - 你不能只是编辑它来支持当今世界的样子。 例如,遗留代码必须在目前可能不存在或不再受支持的硬件上运行。

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.

思慕 2024-07-19 04:18:28

根据优秀的有效处理遗留代码一书的作者 Michael Feathers 的说法,遗留代码是未经测试的代码。 当代码更改时无法知道什么会导致问题。

主要区别
非遗留代码的遗留代码是
测试,或者更确切地说,缺乏测试。 我们
可以稍微了解一下
思想实验:这有多容易
是修改你的代码库,如果它
如果它能告诉你的话,它会反咬一口
你什么时候犯错了? 这将是
很容易,不是吗? 大部分的
害怕做出改变
大型代码库令人恐惧
引入微妙的错误; 害怕
不经意间改变事情。 和
测试,你可以让事情变得更好
有罪不罚。 对我来说,差别是如此
至关重要,它压倒了任何其他
区别。 通过测试,您可以
事情变得更好了。 没有他们,你只是
不知道事情是否进展顺利
更好或更坏。

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.

撩人痒 2024-07-19 04:18:28

没有人会读这个,但我觉得其他答案不太正确:

  1. 它有价值,如果没有用,它早就被扔掉了,
  2. 这很难推理,因为
    1. 缺乏文档,
    2. 无法找到或忘记原始作者(是的,2 个月后您的代码也可以是遗留代码!),
    3. 缺乏测试或类型系统
    4. 不遵循现代实践(即也没有背景可坚持)
  3. 有变更或延长的要求。
    如果不需要更改它,则它不是遗留代码
    因为没人关心它。 它做它的事而没有人
    称之为遗留代码。

Nobody is gonna read this, but I feel the other answers don't get it quite right:

  1. It has value, if it wasn't useful it would've been thrown away long ago
  2. Its hard to reason about because either of
    1. Lack of documentation,
    2. Original author cannot be found or forgot (yes 2 months later your code can be legacy code too!!),
    3. Lack of tests or typesystem
    4. Doesn't follow modern practices (ie no context to hold on too)
  3. There is a requirement to change or extend it.
    If there isn't a requirement to change it, it isn't legacy code
    since nobody cares about it. It does its thing and there is nobody
    around to call it legacy code.
难理解 2024-07-19 04:18:28

一位同事曾经告诉我,遗留代码是指任何不是您自己编写的代码。

可以说,它只是一个贬义词,指的是我们出于某种原因不再喜欢的代码(通常是因为它不酷或不时尚,但它有效)。

TDD 团队可能会建议任何未经测试的代码都是遗留代码。

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.

酒浓于脸红 2024-07-19 04:18:28

旧代码是与不再受支持或制造的操作系统或其他计算机技术相关的源代码。

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

顾北清歌寒 2024-07-19 04:18:28

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

“遗留代码是涉及到不再支持或制造的“

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

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

江南月 2024-07-19 04:18:28

缺少支持(或文档)的任何代码。 可以是:

  • 内联注释
  • 技术文档
  • 口头文档(编写它的人)
  • 记录代码工作原理的单元测试

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
向地狱狂奔 2024-07-19 04:18:28

对我来说,遗留代码是在某种范式转变之前编写的代码。
它可能仍然被广泛使用,但它正在被重构以使其符合要求。
例如,旧的过程代码挂在其他面向对象的系统中。

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.

巴黎盛开的樱花 2024-07-19 04:18:28

当代码(或其他任何东西,实际上)被更新/更好的东西取代时,它就变成了“遗产”,但尽管如此,它仍然在“野外”使用并保持活力。

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

薄暮涼年 2024-07-19 04:18:28

保留遗留代码与其说是一种学术理想,不如说是保留可以工作的代码,无论多么糟糕。 在许多保守的企业情况下,这被认为比扔掉它并从头开始更实际。 更好的是你知道的魔鬼...

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

习ぎ惯性依靠 2024-07-19 04:18:28

遗留代码是为了跟上不断变化的需求而痛苦/昂贵的代码。

发生这种情况的方式有两种:

  1. 代码不适合更改
  2. 代码的语义已交换到芯片上

1) 是两者中更容易识别的一种。 该软件具有根本性的限制,使其无法跟上周围的生态系统的步伐。 例如,围绕 O(n^2) 算法构建的系统不会扩展超过某个点,并且如果需求朝该方向移动,则必须重写。 另一个示例是使用最新操作系统版本不支持的库的代码。

2)较难识别,但所有此类代码都有一个特点,就是人们害怕改变它。 这可能是因为它一开始就写得不好/记录得不好,因为它未经测试,或者因为它很重要并且理解它的原始作者离开了团队。

组成活动代码的 ASCII/Unicode 字符在相关人员的心目中具有语义意义,即“为什么”、“什么”以及某种程度上的“如何”。 遗留代码要么是无主的,要么所有者没有与其大部分相关的意义。 一旦发生这种情况(第二天可能会发生这种情况,而且代码写得很糟糕),要更改此代码,必须有人学习并理解它。 这个过程占最初编写时间的很大一部分。

Legacy code is code that is painful/expensive to keep current with changing requirements.

There are two ways that this can happen:

  1. The code is unsuitable for change
  2. The semantics of the code have been swapped out to silicon

1) is the easier of the two to recognize. It is software that has fundamental limits making it unable to keep up with the ecosystem around it. For example, a system built around O(n^2) algorithm won't scale beyond a certain point and must be re-written if requirements move in that direction. Another example is code using libraries that are not supported on the latest OS versions.

2) Is harder to recognize, but all code of this kind shares the characteristic that people are afraid to change it. This could be because it was badly written/documented to begin with, because it is untested, or because it is non-trivial and the original authors who understood it left the team.

The ASCII/Unicode chars that comprise living code have semantic meaning, the "why's", "what's" and to some degree the "how's", in the minds of people associated with it. Legacy code is either un-owned or the owners do not have meaning associated with large portions of it. Once this happens (and it could happen the next day with really poorly-written code), to change this code, someone must learn it and understand it. This process is a significant fraction of the time it takes to write it in the first place.

瀞厅☆埖开 2024-07-19 04:18:28

当你害怕重构代码的那一天,你的代码就变成了遗留代码。

The day you're afraid to refactor your code is the day when your code has become legacy.

若能看破又如何 2024-07-19 04:18:28

如果满足以下任何或所有条件,我认为代码是“遗留”的:

  • 它是使用落后于当前标准一代的语言或方法编写的
  • 代码完全是一团糟,背后没有规划或设计
  • 它是用过时的语言编写的并且采用过时的、非面向对象的风格
  • 很难找到了解该语言的开发人员,因为它太老了。

与这里的其他一些观点不同,我已经看到很多现代应用程序无需单元测试即可正常工作。 单元测试还没有受到所有人的欢迎。 也许十年后,下一代程序员将审视我们当前的应用程序,并认为它们是“遗留”的,因为不包含单元测试,就像我认为非面向对象的应用程序是遗留的一样。

如果需要对遗留代码库进行少量更改,最好保持原样并顺其自然。 如果应用程序需要重大的功能更改、GUI 检修和/或您找不到任何了解编程语言的人,那么是时候扔掉并重新开始了。 不过,请注意:从头开始重写可能非常耗时,而且很难知道是否已复制所有功能。 您可能希望为旧应用程序和新应用程序编写测试用例和单元测试。

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.

终难遇 2024-07-19 04:18:28

老实说,遗留代码是其他软件构造的任何代码、框架、API,它们不再“酷”了。 例如,COBOL 被一致认为是遗产,而 APL 则不是。 现在,我们还可以证明 COBOL 被视为遗留系统,而 APL 则不然,因为它的安装基数大约是 APL 的 100 万倍。 然而,如果您说您需要处理 APL 代码,那么答复不会是“哦,不,那些遗留的东西”,而是“哦,我的上帝,我猜您在下个世纪不会做任何事情”,看到区别了吗?

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?

柠檬心 2024-07-19 04:18:28

这是软件生态系统中经常(而且非常普遍)出现的通用术语。

嗯,我喜欢将遗留代码视为继承代码。 这只是过去编写的代码。 在大多数情况下,遗留代码不遵循新的/当前的实践,并且通常被认为是过时的。

This is a general term thrown around quite often (and quite generically) in the software ecosystem.

Well, I like to think of legacy code as inherited code. This is simply code that was written in the past. In most cases, legacy code do not follow new/current practices and is often considered archaic.

公布 2024-07-19 04:18:28

遗留代码是指一个多月前编写的任何代码:-)

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

作业与我同在 2024-07-19 04:18:28

通常,任何代码都不是用流行的脚本语言编写的,我只是半开玩笑。

It's often any code that isn't written in the trendy scripting language du jour, and I'm only half joking.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文