IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 0 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New McCabe's complexity metric is utterly fscked
The complexity metric used in the article is:

The complexity of a function is 1 (for the function), plus:


  • 1 for every if, and, and or,
  • 1 for every while or repeat
  • 1 for every for, and
  • 1 for every case of a case statement.


This does not measure complexity -- it just measures how big the syntax tree is. A proper measure of complexity should reflect something like "how hard is it to prove the program implements some specification". For procedural code, the appropriate place to look is at the Floyd-Hoare proof rules, and to track how hard the proof is. (In this style, you establish preconditions and postconditions on each statement in the program, and try to prove that the postcondition is implied by the preconditions and the semantics of the statement.)

For if, and, or, and case, proving that the preconditions imply the postconditions is just a case analysis over the branches. For a for loop, you have to do a proof by induction over the integers the loop variable ranges over. For a while or repeat loop, you need to first figure out what the loop invariants are, and then do the induction. So establishing the correctness of -- ie, figuring out what the code does -- is a lot harder for a while loop than an if statement. Penalizing a case more heavily than a while loop is just nuts.

New While I agree with your sentiment
McCabe measures (among other things - there are a couple of measurements) code pathways.

Given a simple if statement with one condition there are 2 pathways - one if the statement is true, another if it is false.

However, given a if statement with two conditions there are 4 pathways.







con1 = true
con2 = true
con1 = false
con2 = true
con1 = true
con2 = false
con1 = false
con2 = false

Same measurement is used for while loops.

Case statements would have X + 1 conditions where X is the number of possible values the condition can switch on plus the default condition.
New I won't disagree...
But it had the advantage that the book I was looking in used it, and it is simple to understand.

Said book used it because however suboptimal it was, there was a bunch of research that used it.

However some of that research might not have meant quite what it seems on the surface. For instance with a lot of small routines they may get changed more per line in maintainance. But if they implement more functionality per line of code (eg because of less duplication of code), then the lines of code measure is less meaningful.

Cheers,
Ben

PS OK, I admit it. It had the benefit of being easy to extend in a way that got me the conclusion I intuitively feel is right (that shortness matters more in good OO than procedural).
"good ideas and bad code build communities, the other three combinations do not"
- [link|http://archives.real-time.com/pipermail/cocoon-devel/2000-October/003023.html|Stefano Mazzocchi]
     How long should routines be in different kinds of code? - (ben_tilly) - (12)
         Great question - (deSitter) - (2)
             Re: Great question - (JimWeirich) - (1)
                 Re: Great question - (deSitter)
         Are you looking for more discussion? ;) - (FuManChu) - (2)
             The responses that I liked best... - (ben_tilly) - (1)
                 Re: The responses that I liked best... - (JimWeirich)
         Re: How long should routines be in different kinds of code? - (JimWeirich) - (3)
             McCabe's complexity metric is utterly fscked - (neelk) - (2)
                 While I agree with your sentiment - (Simon_Jester)
                 I won't disagree... - (ben_tilly)
         2 pages max for Perl for me - (broomberg)
         My rules of thumb - (tuberculosis)

Allow me to retort!
63 ms