Re: McCabe complexity
- From: roberson@xxxxxxxxxxxxxxxxxx (Walter Roberson)
- Date: Fri, 30 May 2008 23:15:54 +0000 (UTC)
In article <g1proh$40p$1@xxxxxxxxxxxxxxxxxx>,
Kenneth Eaton <Kenneth.dot.Eaton@xxxxxxxxxxxxx> wrote:
It seems clear that the McCabe complexity measure doesn't
like switches all that much, unless they're tiny and
simple. Is this anything other people have seen? Should I
be concerned about this?
Or maybe this is just one of many subjective complexity
measures that I just shouldn't worry about? What are
everyone's thoughts?
I did a little looking around at some of my code, and the
McCabe measure was an absolute minimum of 8 for all but the
most trivial logic. A simple nested-if with all four branches
populated was enough to get up to 8. Anything with a triply-nested if
was 20 or higher.
Now perhaps it is the case that people have to strain a little
to get a triple-nested if straight in their mind, but in terms
of practical programming, a triple-nested 'if' is nothing special,
and deliberately writing code to avoid it would end up
with a lot of fake state variables that would hard to keep
straight, or would require breaking up the code into routines
that had little more than temporal linkage.
Consider this simple and standard functional block:
if we need to do this block of work
result = somefunction(the appropriate variables);
if result indicates failure
display an error message;
return;
end
end
This standard logic will generate a McCabe measure of at least 8.
If there is any but the most trivial surrounding logic, you are going
to blast through the 10 "limit". And yet it is logic that effectively
cannot be reduced in complexity without introducing catch/error:
if you try to push the logic into a subroutine in order to reduce
the complexity, the logic for calling the subroutine will be the same
as the above logic!
--
"Tired minds don't plan well. Sleep first, plan later."
-- Walter Reisch
.
- References:
- McCabe complexity
- From: Kenneth Eaton
- McCabe complexity
- Prev by Date: Re: implicit plot ??
- Next by Date: sine wave generation
- Previous by thread: McCabe complexity
- Next by thread: using surf
- Index(es):
Relevant Pages
|