On Dec 10, 2006, at 1:16 AM, Ovid wrote:

--- Matisse Enzer <[EMAIL PROTECTED]> wrote:
McCabe Complexity
-----------------
Code not in any subroutine::
min:                  1
max                   10
mean:                 1.00
std. deviation:       2.54
median:               1.00

Subroutines/Methods:
min:                  1
max:                  15
avg:                  1.00
std. deviation:       2.60
median:               1.00

Hi Matisse,

Thanks or creating this code.  It looks interesting, though I confess
I'm feeling a little slow.

In reading through the Wikipedia description and
http://www.sei.cmu.edu/str/descriptions/cyclomatic_body.html, I still
don't understand how to interpret the above result.

I think the easy way to understand Cyclomatic Complexity is this: It is a measurement of how many possible paths there are through a chunk of code. So, if there are 3 possible paths through a subroutine then it has a complexity of 3. If you add one "if" statement then the complexity goes up by 1. There are more sophisticated explanations, and, more sophisticated ways of measuring complexity than what my module does, but I think you get the idea:

   sub complexity_of_one {
       my $bar = shift;
       return $bar * 23;
   }

   sub complexity_of_two {
       my $bar = shift;
       if ( $bar->isa('Foo::Bar') ) {
           return $bar->multiply(23);
       }
       return $bar * 23;
   }

   sub complexity_of_two {
       my $bar = shift;
       if ( $bar->isa('Foo::Bar') ) {
           return $bar->multiply(23);
       }
       return $bar * 23;
   }

   sub complexity_of_six {
       my $bar = shift;
       my $total = 0;
       my $type = ref $bar;
       if ( ! $type ) {
           $total = $bar;
       }
       elsif ( $type eq 'ARRAY' ) {
           foreach my $baz ( @{$bar} ) {
               $total += $baz;
           }
       }
       else {
           confess("Don't know how to handle refs to $type");
       }
       return $total;
   }


Also, if your average (mean) is 1.00, how is the standard deviation
greater than that value?

You fund a bug :-)
The countperl script v0.30 is reporting the median, not the mean for the complexity numbers. I'll fix this and release a new version today or tomorrow.
Thanks !

Here's a portion of the corrected report:

./countperl lib/TAPx

Perl files found:                12

Counts
------
total code lines:        1959
lines of non-sub code:   1261
packages found:          14
subs/methods:            98

Subroutine/Method Size
----------------------
min:                  1 lines
max:                  48 lines
mean:                 7.12 lines
std. deviation:       8.24
median:               4.00

McCabe Complexity
-----------------
Code not in any subroutine::
min:                  1
max                   10
mean:                 2.17    <--- FIXED
std. deviation:       2.54
median:               1.00

Subroutines/Methods:
min:                  1
max:                  15
mean:                 2.42    <--- FIXED
std. deviation:       2.60
median:               1.00

Tab-delimited list of subroutines, with most complex at top
-----------------------------------------------------------
complexity      sub     path    size
15      _initialize     lib/TAPx/Parser.pm      48
11      _finish lib/TAPx/Parser.pm      30
11      _switches       lib/TAPx/Parser/Source/Perl.pm  22
10      _aggregate_results      lib/TAPx/Parser.pm      11
10      {code not in named subroutines} lib/TAPx/Parser.pm      626
9       next    lib/TAPx/Parser/Iterator.pm     27
8       _filtered_inc   lib/TAPx/Parser/Source/Perl.pm  15
Etc.

-M

-------------------------------------------------------
Matisse Enzer <[EMAIL PROTECTED]>
http://www.matisse.net/  - http://www.eigenstate.net/



Reply via email to