Cyclomatic Complexity (CC) being the number of execution paths through a function or method. Sriram makes a case for measuring the CC per 100 lines of code (which he calls CC100). This concept of an average CC is interesting but I suggest misguided.
It’s as if I have a choice of writing code with lots of control statements (if, while, case, …, these increase CC) or I can alternatively choose to write it without so much control flow. I suggest this is much more to do with the nature of the problem I’m solving than the way I’m solving it.
The problem is that I can reduce the average CC quite easily without changing the number of branches. For example, I could do a straightforward extract a method to take a block of code with CC 7 out of a function with CC 49 and end up with 2 functions each with CC 7. The average for this block of code goes from 49 to 7!
Now I know what Sriram is after – he’s looking for a way to know if he’s actually reduced the raw complexity of the code by making smart use of inheritance and such like. In this case, he’d be better to count the number of code branches. If he can reduce these and keep the CC below some threshold, you could say that his code is less complex.
CC can only be meaningfully used as a threshold – e.g. it is possible to constuct any program out of funtions none of which have a CC greater than 10 (is there a proof for this?)