Do you find cyclomatic complexity a useful measure?

后端 未结 15 1251
傲寒
傲寒 2020-12-12 22:03

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 pr

相关标签:
15条回答
  • 2020-12-12 22:33

    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.

    The worst we've seen was 87 from a monstrous if-else-if chain in some legacy code we had to take over.

    0 讨论(0)
  • 2020-12-12 22:34

    I haven't used it in a while, but on a previous project it really helped identify potential trouble spots in someone elses code (wouldn't be mine of course!)

    Upon finding the area's to check out, i quickly found numerious problems (also lots of GOTOS would you believe!) with logic and some really strange WTF code.

    Cyclomatic complexity is great for showing areas which probably are doing to much and therefore breaking the single responsibilty prinicpal. These's ideally should be broken up into mulitple functions

    0 讨论(0)
  • 2020-12-12 22:34

    +1 for kenj0418's hit list values.

    The worst I've seen was a 275. There were a couple others over 200 that we were able to refactor down to much smaller CCs; they were still high but it got them pushed further back in line. We didn't have much luck with the 275 beast -- it was (probably still is) a web of if- and switch-statements that was just way too complex. It's only real value is as a step-through when they decide to rebuild the system.

    The exceptions to high CC that I was comfortable with were factories; IMO, they are supposed to have a high CC but only if they are only doing simple object creation and returning.

    0 讨论(0)
提交回复
热议问题