Re: Python code-bloat tool-- warning n00b stuff...
- Original Message From: Robert Kern robert.k...@gmail.com To: python-list@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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python code-bloat tool-- warning n00b stuff...
On Mon, May 18, 2009 at 12:45 PM, david wright 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. TDD does help cut down on code bloat, but not because you are only coding what will actually be used. Rather because of rule #3: 1. Red - write just enough test code to make a test fail 2. Green - write just enough production code to make the test pass 3. Refactor - mercilessly reduce duplication 4. Repeat -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Python code-bloat tool-- warning n00b stuff...
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. Thanks == Anand J Center for Behaviour and Cognitive Sciences University of Allahabad Allahabad-211002 http://sites.google.com/a/cbcs.ac.in/students/anand == The man who is really serious, with the urge to find out what truth is, has no style at all. He lives only in what is. ~Bruce Lee -- http://mail.python.org/mailman/listinfo/python-list
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. 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