Chris Dolan wrote:
> That can't be right.  Negation does not contribute to complexity. 
> Instead, I believe it is the for loop and the exit points that are
> increasing your count.  Consider rewriting the for as ifs and gotos:
> 
>    sub complexity_of_six {
>        my $bar = shift;
>        my $total = 0;
>        my $type = ref $bar;
>        if ( ! $type ) {
>            $total = $bar;
>        }
>        elsif ( $type eq 'ARRAY' ) {
>            my $_i = 0;
>          LOOP:
>            goto DONE if ($_i >= @{$bar});
>            my $baz = $bar->[$_i];
>            $total += $baz;
>            $_i++;
>            goto LOOP;
>          DONE:
>        }
>        else {
>            confess("Don't know how to handle refs to $type");
>        }
>        return $total;
>    }
> 
> Then the decision points are:
>   1) if ( ! $type )
>   2) if ( $type eq 'ARRAY')
>   3) if ($_i >= @{$bar})
>   4) else
> and the end points are
>   1) confess("Don't know how to handle refs to $type");
>   2) return $total
> 
> So I actually count a complexity of 7 (num decision points + num
> endpoints + 1) if I've understood the wiki definition correctly.
>   http://en.wikipedia.org/wiki/Cyclomatic_complexity

Are the else and confess different decision points?  There's no way out of the 
else but the confess.  Similar issue with the return.

Reply via email to