python metrics program/script sample

Peter Hansen peter at engcorp.com
Mon Dec 27 19:29:25 CET 2004


Philippe C. Martin wrote:
> "true" lines of code meant no blanks or comment - pycount calls those "normal 
> source code":

Pycount does not treat a blank line as "normal source code",
at least in the version I'm using.  It quite clearly differentiates
between various types of lines, including a header in the output
which reads as follows:

    lines    code     doc comment   blank  file

(doc and comment are two separate columns, as it distinguishes
between doc-comments, which are comments only by convention,
and real comments).

>>There are a couple of minor known bugs with pycount like: Doc strings must be 
>>tripple-quoted ones otherwise they are classified as normal source code. 

Interesting, but I believe it's a nearly universal convention to
use triple-quoted strings for doc-comments.  I guess if you don't
do that, however, pycount might not be for you.

>>Continuation lines ending with a backslash are not treated at all. Complex 
>>regular expressions (as in pycount itself) can knock the parser down, 
>>quickly. There is a built-in quick-and-dirty solution to this which might 
>>work whenever the problem is on one line only. But in "most cases" it 
>>works...

In areas like this, I consider most attempts to make a line
counter "more sophisticated" are, while well-meaning, often
a waste of time.  For example, if I have a line that is long
enough (read "complex enough") to warrant a line-continuation,
I'm quite happy if a simple line counter decides to call it
two lines (or three, or whatever).  Or one.  It shouldn't be
that big a deal.  "Source lines of code" has at best a tenuous
connection to complexity or other abstract characteristics of
code, so I don't see any reason to spend time on making a
line counter "perfect".  It should probably be used only for
comparative analysis anyway, so as long as it does the same
thing on your entire code base, it ought to be good enough,
IMHO.

> I'll try pycount but the above bugs might mean a lot of rewriting.

I've been using it for quite some time, successfully, without
even being aware there were problems with certain types of
source.  Maybe my code is just relatively standard-looking,
so pycount doesn't have trouble with it...

-Peter



More information about the Python-list mailing list