On Dec 15, 2006, at 7:52 AM, 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; }
Just for the record, Perl::Metrics::Simple gives that code a complexity count of 8. I realize that I'm not actually counting 'ne', 'eq', 'ge', or 'le', which is probably a bug :-)
I'm totally interested in better way(s) to measure this by the way. ------------------------------------------------------- Matisse Enzer <[EMAIL PROTECTED]> http://www.matisse.net/ - http://www.eigenstate.net/
