On 2009-05-16 12:13, anand j wrote:
Hi,
     I am looking for a bunch of rules or a tool that takes the code for
my python class and checks the amount of code bloat and points out where
i can improve. I am a n00b to python and built an application linking
wordnet and graph packages. but somehow have this nagging feeling my
code is too bloated with too many functions..... might just be paranoia
, but worth an investigation i guess.....

Sorry if this is a repeat/trivial question, I could not find any
comprehensive links on google or the mailing list archive that is within
my gmail. Currently, trying to download the other archives and index
using whoosh and try searching it.

Just use Google: "site:mail.python.org code bloat tool"

But basically, such a thing doesn't really exist. It's not really a quantifiable concept. You can use tools like pylint to enforce a simple policy (e.g. "no more than 50 methods per class"), but that's not really the same thing, nor is it something you can't do yourself with a little bit of grepping.

A slightly more interesting and nontrivial metric that you can apply is cyclomatic complexity. Basically, it is the number of independent code paths your each function may go down.

http://en.wikipedia.org/wiki/Cyclomatic_complexity
http://www.traceback.org/2008/03/31/measuring-cyclomatic-complexity-of-python-code/

This will give a not-too-unreasonable measure of how complicated each function is. I don't know if that's what you are getting at with the term "code bloat".

However, there is no substitute for experienced judgment. Show your code to other Pythonistas. What do they think? A quick question to an experienced programmer is usually much more efficient than downloading a tool and trying to interpret its results.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth."
  -- Umberto Eco

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to