Python code-bloat tool-- warning n00b stuff...

david wright david_v_wright at yahoo.com
Mon May 18 12:45:01 EDT 2009


----- Original Message ----

From: Robert Kern <robert.kern at gmail.com>
To: python-list at python.org
Sent: Saturday, May 16, 2009 3:55:11 PM
Subject: Re: Python code-bloat tool-- warning n00b stuff...

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.

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".


---


I would suggest looking into TDD (test driven development). 

This technique would be a good fit to eliminate you feeling of code bloat, in TDD you only write the necessary amount
of code to make your test pass, hence you never write code that is not going to be utilized. 

It takes a little while to get used to this technique ( also, it can be much more difficult to apply in some situations) but it's well worth the effort. :). You'll have no trouble finding tons of resources for this topic.



More information about the Python-list mailing list