Cyclomatic Complexity

Washburn, John
Fri Feb 18 08:24:00 GMT 2000

< > 

Has there been any progress in implementing this 25 year old idea?  I
realize calculating cyclomatic complexity is as difficult as compiling code,
but that is what a compiler does.  It makes sense to spit out such a useful
metric at the same time the code is compiled.  After all if you climb Mt.
Everest what's another 6 feet?

Cyclomatic complex is strongly correlated with defect density.  It is a
cheap statistic to calculate once the program is processed into an Abstract
Syntax Tree and before Optimizations of the program tree (e.g. constant
sub-expression removal) are performed.  

It would be nice if a compiler could emit a warning regarding the functions
with complexity value greater than some threshold.  These functions would
then be candidates for decomposition or placed on the 'Handle with Care'
list of suspect functions.  'Handle with Care' functions would be a
candidates for formal code reviews, formal testing, and other quality and
review processes.

Maybe even the compiler implementation itself could be examined for overly
complex coding.

More information about the Gcc mailing list