python vs perl lines of code

Edward Elliott nobody at
Sat May 20 00:57:29 CEST 2006

akameswaran at wrote:

> But first things first... and this one I think is solvable - their has
> got to be an equitable way to count how much code was written - maybe
> it isn't lines maybe it is.... 
> ANd that's it - not can we make a qualitative 
> statement beyond that.  But simply can we quanitfy the amount of code
> in some fashion that allows a reasonable comparison?

Maybe a count of identifiers and keywords.  Symbols like ()[];,. don't add
much beyond where to parse the code.  And even though operators like
+-*/^&| et al convey semantics, they need expressions to operate on, in
which the identifiers are already counted.  You could make a case either
way but I'd leave them out for simplicity.

The question is how to count explicit names like module.class.func; should
that be 1 identifier or 3?  Counting as 3 would reward things like "from X
import *" which are generally frowned on in python while 'use MOD qw(id)'
is encouraged in perl.  I'm inclined to just count explicit names as 1. 
It's still a single object, and I'm not sure a.b.c is more work to process
than just c anyway.  If you don't care where c is, they're equivalent.  If
you do care, you've got to remember where the naked c lives, so it just
shifts the work from the code to your brain.

Then you've got problems with implicit variables/operations.  Should perl's
$_ be counted?  What about python's copy-slice [:]?  You can drive yourself
crazy worrying about such things, so I'd just start with the simple case by
ignoring them.

This id-keyword count would appear to be related to how much information you
must process to read through the code.  Unfortunately you need a parser for
each language to measure it.  If anyone can provide such a beast, I'll
gladly run it against my code.  In the meantime, line/char counts are the
best I've got.

Edward Elliott
UC Berkeley School of Law (Boalt Hall)
complangpython at eddeye dot net

More information about the Python-list mailing list