可用的代码公制系统?
除了圈复杂度之外,还存在哪些其他代码度量系统?
Besides Cyclomatic Complexity what other code metric systems exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
除了圈复杂度之外,还存在哪些其他代码度量系统?
Besides Cyclomatic Complexity what other code metric systems exist?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
代码指标
您认为圈复杂度是一个有用的衡量标准吗?
什么代码指标让您相信所提供的代码是“蹩脚”?
Code metrics
Do you find cyclomatic complexity a useful measure?
What code metric(s) convince you that provided code is “crappy”?
维基百科提供了一个
指标简单概述。
实际上有很多很多的指标。事实上,将源代码映射到测量尺度(整数、实数、分类枚举)的源代码的任何函数都可以被视为度量。
大多数代码指标的问题在于它们往往与 SLOC 成正比,如果是这样的话,SLOC 也一样好。对于指标最好的做法是立即测量您的代码,并跟踪指标如何随时间变化;趋势,无论是上升还是下降,都会比指标本身告诉你更多的信息。向上意味着坏消息;向上意味着坏消息。代码变得越来越复杂。
将代码(复杂性)指标与错误率结合起来考虑也很有用。模块的高度复杂性以及同一模块中的高错误率表明,重新设计该模块可能是防止该领域出现进一步问题的好主意。高复杂性和低错误率表明代码看起来很可怕,但事实并非如此。
Wikipedia provides a
simple overview of metrics.
There are actually lots, and lots of metrics. In fact, any function of the source code that maps source code to a measurement scale (integers, reals, classification enums) can be considered to be a metric.
The problem with most code metrics is that they tend to be proportional to SLOC, and if that's the case, SLOC is just as good. What is best to do with metrics is to measure your code now, and track how the metric changes over time; the trend, up or down, will tell you almost more than the metric will itself. Up means bad news; the code is getting more complicated.
It is also useful to consider code (complexity) metrics in conjunction with bug rates. A high complexity in a module, and and high bug rate in the same module, suggests that a redesign of that module may be a good idea to prevent further troubles in the field. High complexity and low bug rates would suggest the code looks scary but isn't.
Halstead 的软件科学 是一个出色的指标套件,可以让您深入了解你的程序的实际结构。
Card and Glass 也创建了一个模型,但我不确定该模型是否可以在书籍之外使用。无论如何我都会寻找它。
Halstead's Software Science is a fantastic metrics suite that can give you interesting insight into the actual constructs of your program.
There is a model created by Card and Glass as well, but I'm not sure if that is available outside of books. I would look for it regardless.
查看 Visual Studio 2012 中集成的 NDepend 工具支持的 82 个代码指标定义, 2010 年和 2008 年。免责声明:我是该工具的开发人员之一
请注意,这些代码指标可以通过 CQLinq 查询和规则来定义您自己的自定义代码指标。
例如,除循环复杂度之外的一种流行代码指标是 废话指标。基本上,CRAP 将蹩脚代码定义为复杂的方法(具有高循环复杂度),测试很难覆盖。 默认 CQLinq 规则,用于定义 CRAP< /em> 指标是:
Have a look at the 82 code metrics definitions supported by the tool NDepend integrated in Visual Studio 2012, 2010 and 2008. Disclaimer: I am one of the developers of the tool
Notice that these code metrics can be composed through CQLinq queries and rules to define your own custom code metrics.
For example, one popular code metric other than Cyclomatic Complexity is the C.R.A.P metric. Basically, the C.R.A.P define crappy code as complex methods (with high Cyclomatic Complexity), poorly covered by tests. The default CQLinq rule to define the C.R.A.P metric is: