Rob Kinyon | 8 Dec 14:27
Picon
Gravatar

Re: FW: Code and block size as complexity metrics

http://www.perlmonks.org/?node_id=413087 has a discussion of
Cylcomatic Complexity, which seems to be exactly what we're trying to
do here ...

On Wed, 24 Nov 2004 13:20:57 +1100, Adam Kennedy <adam <at> phase-n.com> wrote:
> > I've got the basic tokens/block thing going in an exploration script.
> > One thing I'm noticing is that find() flattens out your parse-tree.
> > Having the ability to access the parent-node may end up being nice,
> > but I'm still feeling my way through the problem-space, so don't code
> > anything based on what I say just yet.
> 
> It doesn't flatten it out as such, it just returned a list of pointers
> to the various elements you asked for in the tree.
> 
> http://search.cpan.org/~adamk/PPI-0.831/lib/PPI/Element.pm
> 
> The tree itself still exists and is not modified, and you can still call
> any of the "going up the tree" methods.
> 
> $Element->parent      # Immediate parent
> $Element->top         # Top of the PDOM tree (should be a ::Document)
> $Element->statement   # Parent statement
> 
> > Some documentation on what "significant" means would be nice. Also, if
> > significant() and prune() could play together, that would be cool. I'm
> > finding I like to do something like:
> >
> > my $doc = PPI::Document->read( $filename );
> > $doc->prune( "PPI::Token::$_" ) for qw( Comment Whitespace );
> 
(Continue reading)

Stevan Little | 8 Dec 20:49
Favicon

Re: Code and block size as complexity metrics

(Note this is cross posted on perlmonks as well)

So I was reading the Cylcomatic Complexity thread on perl monks, and it 
occured to me that B::Concise actually gives up some of the necessary 
information (at least I think it does).

Given this code:

	print "Hello World";

I got this output:

stevan% perl -MO=Concise test.pl
6  <@> leave[1 ref] vKP/REFC ->(end)
1     <0> enter ->2
2     <;> nextstate(main 1 test.pl:3) v ->3
5     <@> print vK ->6
3        <0> pushmark s ->4
4        <$> const[PV "Hello World"] s ->5

Now I freely admit that both my understanding of Cylcomatic Complexity 
and B::Concise's output are most likely radically flawed, but I am 
going to ramble a bit here anyway.

Using this definition for CC (Cylcomatic Complexity)

	Cyclomatic complexity may be considered a broad measure of soundness 
and
	confidence for a program. Introduced by Thomas McCabe in 1976, it 
measures
(Continue reading)


Gmane