Women in Technology

Hear us Roar

  Code Improvement Through Cyclomatic Complexity
Subject:   code complexity
Date:   2004-06-19 17:05:13
From:   swing_developer
Well it's a poor measurement of complexity on the face of it, because it assigns a point for entering a method.

This means that if I refactor that 200-line mess of a method into the 25 calls to specialized methods it should have been in the first place, I am adding *complexity*. Come on. Just the opposite; I am reducing complexity and increasing comprehensiblity.

Main Topics Oldest First

Showing messages 1 through 1 of 1.

  • code complexity
    2004-06-19 18:09:42  aglover [View]

    Cyclomatic Complexity, like most metrics, is merely a guide. A 200 line method, foo, would most likely be flagged with elevated complexity; however, if you pushed that code into 25 separate methods, you have, in effect, lowered foo's complexity and pushed that complexity into succinct methods, which are most likely far easier to isolate and consequently, test. The key point, however, is that those separate calls to 25 methods do not increase the value of Cyclomatic Complexity for method foo. The point assigned in Cyclomatic Complexity for foo is for entering foo, not for foo calling other methods. If foo had a Cyclomatic Complexity of x and called 25 methods, if one added 25 additional calls to methods (and didn't add any conditionals) foo's value is still x.