comp.lang.ada
 help / color / mirror / Atom feed
From: agate!howland.reston.ans.net!darwin.sura.net!haven.umd.edu!news.umbc.edu! nobody@ucbvax.Berkeley.EDU  (Mike Berman)
Subject: Re: McCabe package for Ada?
Date: 19 May 93 21:18:40 GMT	[thread overview]
Message-ID: <1te87gINNt5f@umbc7.umbc.edu> (raw)

On the topic of McCabe complexity, groleau@e7sa.crd.ge.com (Wes Groleau
X7574) writes:

>McCabe scores are not by themselves a very useful indication of Ada quality.
>However, they can be of some use.

>P.S. One thing McCabe doesn't show is what I call "hidden" complexity.
>Hidden, because it doesn't show on a flow chart or path graph.  This kind of
>complexity is produced by a technique more than one of my former colleagues
>was fond of:  That of declaring lots of "flag" variables, and using them to
>control branching at a point far away from where they were set.

While a high McCabe score usually indicates a problem area, a low score
does not necessarily indicate a lack of one. The tradeoff for high
complexity may be an increase in the number of modules, to no benefit
(and often detriment).

Consider the following degenerate case:

	case X is  -- assume X : Integer range 1..4
	when 1 => Do_Something;
	when 2 => Do_Something_Else;
	when 3 => Do_Something_Even_Different;
	when 4 => Do_Yet_A_Fourth_Thing;
	end case;

This statement would add 3 to the complexity of a module containing it.

It could be replaced with the following roughly equivalent code:

	procedure Check_1 is
	begin
	   if X=1 then -- yes, X globally visible for the sake of
	               -- example
	      Do_Something;
	   else
	      Check_2;
	   end if;
	end Check_1;

	procedure Check_2 is
	begin
	   if X=2 then
	      Do_Something_Else;
	   else
	      Check_3;
	   end if;
	end Check_2;

	procedure Check_3 is
	begin
	   if X=3 then
	      Do_Something_Even_Different;
	   else
	      Do_Yet_A_Fourth_Thing;
	   end if;
	end Check_3;

The above scheme results in no added complexity to the module containing
the original case statement, now replaced by a call to Check_1. Each
called module has complexity 2, cleverly eluding the McCabe complexity <
10 check.

The above example is not meant to be realistic, but I have seen cases in
actual code that sure do come close. 

The point of this post is to say that McCabe complexity analysis is
useful, but should be supplemented by a suite of tools to look at code
from other perspectives. The cyclomatic complexity measure, _by itself_,
tells you nothing (as Wes pointed out), especially if a development
community knows that it is the only metric being applied (then the above
transformation is done solely for the purposes of reducing the complexity
score).

-- 
Mike Berman
University of Maryland, Baltimore County	Fastrak Training, Inc.
berman@umbc.edu					(301)924-0050

             reply	other threads:[~1993-05-19 21:18 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-05-19 21:18 agate!howland.reston.ans.net!darwin.sura.net!haven.umd.edu!news.umbc.edu! [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-06-07 18:43 McCabe package for Ada? sgi!fido.asd.sgi.com!dblues!jackr
1993-06-05 19:29 David Boyd
1993-06-04 23:53 Kevin Sullivan
1993-06-04 22:07 dog.ee.lbl.gov!network.ucsd.edu!swrinde!cs.utexas.edu!csc.ti.com!tilde.cs
1993-06-04 21:44 Ala n R. Weiss
1993-06-04 21:25 Dani Zweig
1993-06-04 15:47 agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!w
1993-06-04  6:24 Dani Zweig
1993-06-03 19:47 dog.ee.lbl.gov!network.ucsd.edu!sdd.hp.com!portal!lisburn!jaime
1993-05-27 17:55 Laurence VanDolsen
1993-05-26 22:42 David Boyd
1993-05-26 20:44 Wes Groleau X7574
1993-05-25 10:52 pipex!uknet!glasgow!unix.brighton.ac.uk!wjmc
1993-05-24 19:36 Alex Blakemore
1993-05-24  0:33 mole-end!mat
1993-05-19 23:04 David Boyd
1993-05-19 22:09 David Boyd
1993-05-19 20:03 Wes Groleau X7574
1993-05-19 15:20 cis.ohio-state.edu!magnus.acs.ohio-state.edu!usenet.ins.cwru.edu!howland.
1993-05-19  0:44 sgi!fido.asd.sgi.com!dblues!jackr
1993-05-18 23:42 David Boyd
1993-05-18 21:26 dog.ee.lbl.gov!overload.lbl.gov!agate!howland.reston.ans.net!ux1.cso.uiuc
1993-05-18 19:24 dog.ee.lbl.gov!network.ucsd.edu!usc!howland.reston.ans.net!europa.eng.gte
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox