您发现圈复杂度是一种有用的措施吗? [英] Do you find cyclomatic complexity a useful measure?
问题描述
我一直在测量大型代码库的循环复杂度.
I've been playing around with measuring the cyclomatic complexity of a big code base.
循环复杂度是通过程序源代码的线性独立路径的数量,并且有许多免费工具供您选择.
Cyclomatic complexity is the number of linearly independent paths through a program's source code and there are lots of free tools for your language of choice.
结果有趣但并不奇怪.就是说,我知道最毛的部分实际上是最复杂的(评分> 50).但是我发现有用的是,为每种方法分配了一个具体的错误"编号,这是我在决定从何处开始重构时可以指向的东西.
The results are interesting but not surprising. That is, the parts I know to be the hairiest were in fact the most complex (with a rating of > 50). But what I am finding useful is that a concrete "badness" number is assigned to each method as something I can point to when deciding where to start refactoring.
您使用圈复杂度吗?您找到的最复杂的代码是什么?
Do you use cyclomatic complexity? What's the most complex bit of code you found?
推荐答案
我们毫不留情地进行重构,并将循环复杂性用作在命中列表"上获取代码的指标之一. 1-6并不表示复杂性(尽管可能由于其他原因而受到质疑),7-9值得怀疑,并且除非另有证明,否则任何超过10的方法都被认为是不好的.
We refactor mercilessly, and use Cyclomatic complexity as one of the metrics that gets code on our 'hit list'. 1-6 we don't flag for complexity (although it could get questioned for other reasons), 7-9 is questionable, and any method over 10 is assumed to be bad unless proven otherwise.
我们看到的最糟糕的情况是,在我们不得不接管的一些旧代码中,一条巨大的if-else-if链中有87条.
The worst we've seen was 87 from a monstrous if-else-if chain in some legacy code we had to take over.
这篇关于您发现圈复杂度是一种有用的措施吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!