如何定义“不需要的代码”?

发布于 2024-07-14 17:53:37 字数 108 浏览 6 评论 0原文

您如何定义“不需要的代码”?


编辑:

恕我直言,任何具有 0 个活动调用成员(递归检查)的代码成员都是不需要的代码。 (函数、方法、属性、变量都是成员)

How would you define "unwanted code"?


Edit:

IMHO, Any code member with 0 active calling members (checked recursively) is unwanted code. (functions, methods, properties, variables are members)

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

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

发布评论

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

评论(8

寂寞花火° 2024-07-21 17:53:37

这是我对不需要的代码的定义:

  • 不执行的代码是死重。 (除非它是您实际代码的[恶意]有效负载,但那是另一个故事了:-))
  • 重复多次的代码会增加产品的成本。
  • 无法进行回归测试的代码也会增加产品的成本。

您可以删除此类代码或重构它,但您不想保留它。

Here's my definition of unwanted code:

  • A code that does not execute is a dead weight. (Unless it's a [malicious] payload for your actual code, but that's another story :-))
  • A code that repeats multiple times is increasing the cost of the product.
  • A code that cannot be regression tested is increasing the cost of the product as well.

You can either remove such code or refactor it, but you don't want to keep it as it is around.

£噩梦荏苒 2024-07-21 17:53:37

0 个活跃通话,近期不可能使用。 由于我使用 SVN(源代码管理),所以我宁愿永远不要注释掉任何内容,以防以后需要它。

0 active calls and no possibility of use in near future. And I prefer to never comment out anything in case I need for it later since I use SVN (source control).

魂ガ小子 2024-07-21 17:53:37

就像您在另一个线程中所说的那样,根本不在任何地方使用的代码几乎是不需要的。 至于如何找到它,如果您使用的是 Java,我建议您使用 FindBugs 或 CheckStyle,因为这些工具会检查函数是否在任何地方使用,如果没有则将其标记为未使用。 非常适合摆脱不必要的体重。

Like you said in the other thread, code that is not used anywhere at all is pretty much unwanted. As for how to find it I'd suggest FindBugs or CheckStyle if you were using Java, for example, since these tools check to see if a function is used anywhere and marks it as non-used if it isn't. Very nice for getting rid of unnecessary weight.

娜些时光,永不杰束 2024-07-21 17:53:37

经过短暂思考后,我想到了这三点:

  • 它可能是应该重构的代码,
  • 它可能是不再被调用的代码(早期版本的遗留物),
  • 它可能是不适用于您的风格的代码 -指南和编码方式

我敢打赌还有很多,但这就是我定义不需要的代码的方式。

Well after shortly thinking about it I came up with these three points:

  • it can be code that should be refactored
  • it can be code that is not called any more (leftovers from earlier versions)
  • it can be code that does not apply to your style-guide and way-of-coding

I bet there is a lot more but, that's how I'd define unwanted code.

好菇凉咱不稀罕他 2024-07-21 17:53:37

在java中,我会用@Deprecated标记方法或类。

In java i'd mark the method or class with @Deprecated.

李白 2024-07-21 17:53:37

没有活动调用成员的任何 PRIVATE 代码成员(递归检查)。 否则你不知道你的代码是否没有在你的分析范围之外使用。

Any PRIVATE code member with no active calling members (checked recursively). Otherwise you do not know if your code is not used out of your scope analysis.

凡间太子 2024-07-21 17:53:37

有些东西已经发布了,但这里还有另一个:
几乎做同样事情的函数。 (只有一个小的变量变化,因此整个函数被复制粘贴并且该变量被更改)

Some things are already posted but here's another:
Functions that almost do the same thing. (only a small variable change and therefore the whole functions is copy pasted and that variable is changed)

穿透光 2024-07-21 17:53:37

通常我会告诉编译器尽可能地发出烦人的噪音,它会选择我需要检查的 60% 的内容。 几个月前未使用的函数(在与 VCS 检查后)通常会被淘汰,除非它们的作者告诉我它们何时会实际使用。 缺少原型的东西也立即受到怀疑。

我认为尝试实现自动房屋清洁就像尝试制作一个 USB 设备来保证您“安全”地玩 俄罗斯轮盘赌

最难检查的部分是添加到构建系统中的组件,很少有人注意到这些,未使用的杂物被留下来收集苔藓。

除此之外,我通常想要代码,我只希望其作者对其进行一些重构,并使他们的风格与项目的其余部分相同。

另一个有用的工具是 doxygen,它确实可以帮助您(直观地)查看源树中的关系..但是,如果它设置为不提取静态符号/对象,那么它不会非常彻底。

Usually I tell my compiler to be as annoyingly noisy as possible, that picks 60% of stuff that I need to examine. Unused functions that are months old (after checking with the VCS) usually get ousted, unless their author tells me when they'll actually be used. Stuff missing prototypes is also instantly suspect.

I think trying to implement automated house cleaning is like trying to make a USB device that guarantees that you 'safely' play Russian Roulette.

The hardest part to check are components added to the build system, few people notice those and unused kludges are left to gather moss.

Beyond that, I typically WANT the code, I just want its author to refactor it a bit and make their style the same as the rest of the project.

Another helpful tool is doxygen, which does help you (visually) see relations in the source tree.. however, if its set at not extracting static symbols / objects, its not going to be very thorough.

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