great coding anecdote (via reddit)
I remembered it as "cyclometric complexity" and thought you were all nitpicking on the spelling.
It's a useful concept. If a function gets cc > 10, think about refactoring.
So basically splitting it out into two low temperature washes is better than one high temperature?
>> If a function gets cc > 10, think about refactoring. <<
A couple of jobs ago, we had a method that was a 54.
*That* was a scary method to maintain.
March 30th, 2007 9:52am
of course, it can be misleading, like long switch cases and so on. but then a dispatch table is often a better way, anyhow.
how do you calculate Cyclomatic complexity?
the post suggests a few minutes with perl and i could have per function Cyclomatic complexity? Any help?
> how do you calculate Cyclomatic complexity?
He aint gonna tell you. That's how he gets the big bucks.
No, it's actually very simple.
Start at 1. Then add one for each "IF". Add one for each "ELSE". If you get a 'case' or 'switch' statement, add one for each. Add one for each WHILE/REPEAT/.
That's it. Cyclomatic complexity -- the number of decisions made in a module. Or, the number of 'loops' in the decision tree.
McCabe makes his money off selling software that will do this for entire systems of software.
The AVERAGE complexity was 43? The good guy's was 22?
That place must be a nightmare. I wonder what the highest was.
The danger in paying too much attention to Cyclomatic complexity, is that you end up with a zillion methods that don't accomplish very much.
I would say something between 12 and 20 is about right.
March 30th, 2007 2:04pm
one would think there would be an eclipse plugin. the tools for this are pretty trivial (perl). I do wonder how cc deals with class hierarchies.
"The danger in paying too much attention to Cyclomatic complexity, is that you end up with a zillion methods that don't accomplish very much. "
provided that the things they do are useful by themselves, I'd say that that is a good thing.