在大型项目中处理可能可重用的遗留代码的正确礼仪是什么?

发布于 2024-07-20 18:30:42 字数 88 浏览 4 评论 0原文

我一直想知道解决这种情况的最佳方法是什么。 如果有人决定再次将该功能添加到项目中,最好的方法是将旧代码保留在注释块中,还是应该删除此代码以保持源代码干净和可读?

I have been wondering what is the best way to tackle this situation. Is the best way to leave the old code in a comment block in case someone decides to add that functionality into the project again, or should this code be deleted for the purposes of keeping the source code clean and readable?

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

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

发布评论

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

评论(2

通知家属抬走 2024-07-27 18:30:42

这是重复的,但我没有时间找到重复的。

这也不是特定于遗留代码的。 所有代码都是遗留代码,直到不再使用。

答案是:使用源代码管理。 这就是它的用途。 源文件中的文本应该是当前正在执行的文本。 没有其他的。

This is a duplicate, but I don't have time to find the duplicates.

This also is not specific to legacy code. All code is legacy code, until it is no longer used.

The answer is: use source control. That's what it's for. The text in your source files should be what's currently being executed. Nothing else.

狠疯拽 2024-07-27 18:30:42

只要您使用源代码管理,我认为最好删除未使用的代码。 将注释掉的代码与活动代码混合在一起“以防万一”可能会使文件难以维护。
如果其余代码正在积极开发中,那么带注释的代码很可能很快就会被抛在后面。 如果僵尸代码被取消注释,它可能根本无法工作,或者复活的代码可能会导致难以检测的问题。

我参与过“不删除”项目。 就像在垃圾场工作一样。 搜索代码让我想哭。 有些方法包含的注释代码多于编译代码。 疯狂!

As long as you are using source control, I think it's better to delete unused code. Leaving commented-out code mixed in with active code "just in case" can leave the file difficult to maintian.
If the rest of the code is under active development, chances are that the commented code will quickly get left behind. If the zombie code ever is uncommented it might not work at all, or the resurrected code might cause a difficult-to-detect problem.

I've worked on "do not delete" projects. It was like working in a junkyard. Searching the code made me want to cry. Some methods contained more commented code than compiling code. Madness!

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