Re: McCabe complexity



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
.



Relevant Pages

  • Re: Complexity (was Re: Convert DB2 on z/OS to Oracle on z/Linux?)
    ... but the benefits far outweigh the complexity. ... write your own subroutine and be done with it. ... Publishing web service endpoints in a registry is a good thing to do because ... don't need to set up WSDL and register the service, ...
    (bit.listserv.ibm-main)
  • Re: Name Dropping Without Shame
    ... recognize that the places where my science gets "weird" are places on ... complexity is directly related to behavioural complexity is naive far ... food and other necessities that has given rise to the current system ... fine plan, as far as I can tell. ...
    (misc.writing)
  • repeated calls to fftw
    ... This is related to repeated calls to small-size FFT using FFTW ... I have written a subroutine that only creates the ... But it would crash if I call it from another subroutine. ... I have to generate another plan to avoid the crash. ...
    (comp.lang.fortran)
  • Re: Rebuidling a paper/pencil schedule in MSP2003
    ... Hopefully at this point you can convince the planning staff to start again and build the schedule model/estimate in Project. ... In addition to providing some aids for dealing with the schedule complexity, this approach will get you to one plan in which you can focus on the plan instead of focusing on two plans and then having to resolve differences. ...
    (microsoft.public.project)
  • Re: repeated calls to fftw
    ... > This is related to repeated calls to small-size FFT using FFTW ... I have written a subroutine that only creates the ... > I have to generate another plan to avoid the crash. ...
    (comp.lang.fortran)