代码复杂性分析工具超越了圈复杂性 [英] Code complexity analysis tools beyond cyclomatic complexity

查看:179
本文介绍了代码复杂性分析工具超越了圈复杂性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然圈复杂度是一个值得衡量的指标,但我倾向于发现它是识别难以维护的代码的糟糕工具。特别是,我倾向于发现它只突出了某些类型的代码(例如解析器),并且错过了很难的递归,线程和耦合问题以及许多已经定义的反模式。

While cyclomatic complexity is a worthwhile metric, I tend to find it to be a poor tool for identifying difficult to maintain code. In particular, I tend to find it just highlights certain types of code (e.g. parsers) and misses difficult recursion, threading and coupling problems as well as many of the anti-patterns that have been defined.

还有哪些其他工具可用于识别有问题的Java代码?

What other tools are available to identify problematic Java code ?

注意,我们已经使用了PMD和FindBugs,我认为它们非常适合方法级问题识别。

Note, we already use PMD and FindBugs which I believe are great for method level problem identification.

推荐答案

我的经验是,在查看代码可维护性时最重要的指标是:

My experience is that the most important metrics when looking at code maintainability are:


  • Cyclomatic Complexity,to识别可能难以理解/修改的大块代码。

  • 嵌套深度,找到类似的点(高嵌套深度自动高CC,但不一定相反,所以对两者的评分都很重要。)

  • 扇入/退出,以更好地了解方法/类之间的关系以及各个方法的实际重要性。

在检查由他人编写的代码时,包含动态技术通常很有用。只需通过分析器/代码覆盖工具运行常见的使用场景即可发现:

When examining code that was written by others, it is often useful to include dynamic techniques. Simply run common usage scenarios through a profiler/code coverage tool to discover:


  • 实际执行的代码很多(分析器很适合这个,只需忽略时间信息,然后查看命中计数。)。

  • 代码覆盖很容易找到(几乎)死代码。为了防止你花时间重构很少执行的代码。

通常的嫌疑人,如任何分析器,代码覆盖率和指标工具通常可以帮助您获取进行这些评估所需的数据。

The usual suspects such as any profiler, code coverage and metrics tool will usually help you with getting the data required to make these assessments.

这篇关于代码复杂性分析工具超越了圈复杂性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆