Matt,
To be honest, I was thinking something more along the lines of using Devel::Size to discern the memory-size of each subroutine package. This seemed to me maybe to be a better way to measure since it is possible through creative formatting and long variable names to end up with what looks like a lot of lines but is actually not that much code.
The only problem, Devel::Size does not count the size of subroutines. (see the docs http://search.cpan.org/~dsugal/Devel-Size-0.58/Size.pm)
However, fear not, it may still be possible. Using the B modules, one could actually traverse the opcode tree and count the number of opcodes in each function. This would actually be better than raw memory size since it would be more related to perl itself.
Steve
On Nov 19, 2004, at 9:18 PM, Matt Olson wrote:
On Thu, 18 Nov 2004 14:55:04 -0500, Stevan Little <[EMAIL PROTECTED]> wrote:Incidentally, 'ensure'- and 'sanity'-block size looks like it might be
a useful metric for figuring out whether a particular subroutine is
too complex. If you don't want to fill out that 'ensure' block
because you know it's going to be a beast, maybe you're trying to do
too much in one place.
This is actually an excellent idea for just a code metrics tool in
general. Something which would loop through your packages and count the
code size for each subroutine.
Code-folding in vim (a feature that I Cannot Live Without(tm)) does that for me; I have vim fold on indent level, so it's pretty easy to just close all the folds, flip through the file, and check for any fold that says it's longer than n lines (where n varies depending on the language and the programmer's sobriety). I wonder how you'd automate that... going through with a screen-scraper would really suck.
While we're at it, if you're using code size as a metric, you should probably apply it to blocks, not just to subs. Blocks inside functions should be fairly small, with obvious exceptions for constructors and such. On the other hand, long blocks might be excusable if they consist of many smaller blocks, all relatively compact. The idea is that each level of scope acts sort of as a conceptual bucket: if you only have to deal with a few items at any given scope, you might not care that those items contain hundreds of lines. (Obviously, this is a metric that can be horribly abused.) Does that sound useful?
--Matt
_______________________________________________ sw-design mailing list [EMAIL PROTECTED] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design
_______________________________________________ sw-design mailing list [EMAIL PROTECTED] http://metaperl.com/cgi-bin/mailman/listinfo/sw-design
