问题描述
这是我现在看到每然后一个词是圈复杂度。在这里,所以我看到了有关如何计算语言X的CC或者我该怎么做Y中的CC的最低金额的一些问题,但我不知道我真正理解它是什么。
A term that I see every now and then is "Cyclomatic Complexity". Here on SO I saw some Questions about "how to calculate the CC of Language X" or "How do I do Y with the minimum amount of CC", but I'm not sure I really understand what it is.
在,我看到基本上说的方法决定的数量的解释。每个如果,,和放大器;&放大器;等等加+1到CC分数)是真的呢?如果是的,这是为什么坏我可以看到,人们可能希望保留if语句的数量?相当低,以保持code容易理解,但是这是真的一切呢?
On the NDepend Website, I saw an explanation that basically says "The number of decisions in a method. Each if, for, && etc. adds +1 to the CC "score"). Is that really it? If yes, why is this bad? I can see that one might want to keep the number of if-statements fairly low to keep the code easy to understand, but is this really everything to it?
或者是有一些深层次的概念呢?
Or is there some deeper concept to it?
推荐答案
我不知道一个更深的概念。我相信这是一般的维修性指标的背景下考虑。地区的分行有一个特定的方法中,更困难的是保持该方法的操作(一般)的心理模型。
I'm not aware of a deeper concept. I believe it's generally considered in the context of a maintainability index. The more branches there are within a particular method, the more difficult it is to maintain a mental model of that method's operation (generally).
方法也更难获得完整code覆盖在单元测试。 (感谢!)
Methods with higher cyclomatic complexity are also more difficult to obtain full code coverage on in unit tests. (Thanks Mark W!)
这带来了可维护性的所有其他方面的,当然。错误的可能性/回归/等等。其核心理念是pretty直线前进,虽然。
That brings all the other aspects of maintainability in, of course. Likelihood of errors/regressions/so forth. The core concept is pretty straight-forward, though.
这篇关于什么是圈复杂度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!