views:

524

answers:

4

When digging into legacy Python code and writing Python code myself, I often use pylint. I'm also using Clone Digger. I've recently started to use rope, which is a library for automated refactoring.

But I'm looking for something else than rope. I would prefer a tool that just makes suggestions about possible refactorings: names the refactoring, optionally provides a short description of it (great for learning purposes), highlights the code section and lets me do the refactoring myself. Is there such a tool?

+1  A: 

Check out bicycle repair man http://bicyclerepair.sourceforge.net/

What is Bicycle Repair Man? The Bicycle Repair Man project is an attempt to create refactoring browser functionality for python. It is packaged as a library that can be added to IDEs and editors to provide refactoring capabilities. Bindings for Emacs and Vi are included with the package.

Never used it myself, but have read about it. Sounds like what you are looking for.

BicycleRepairMan is like rope, but older and has less features than rope. It's not what I'm looking for. I've used BRM in the past. I didn't mention it in my question because rope replaced it.
Anonymous
A: 

NetBeans has an early access version that supports Python, and it is rather nice. It has some basic refactoring tools that I found the be useful. As an added bonus it works on Windows, Linux, Mac OS X and Solaris.

Check it out at: http://www.netbeans.org/features/python/

Gourneau
I don't see anything at the reference you give that would suggest it does what the question asks for: giving suggestions to the programmer as to *which* refactorings to perform, at what specific point in their code.
bignose
+1  A: 

I don't if that type of tool exists in any specific language, although the concept was mentioned in Martin Fowler's refactoring book (web reference).

The best tool I know of that currently exists is cyclomatic complexity. This article implements a cyclomatic complexity counter for python.

The other easy metric to target is method/function length, number of attributes of objects/classes and number of parameters to functions, if I recall, pylint already counted those.

Ryan
+1  A: 

Oh Forget about your tool, instead use TDD and a good book like refactoring to design patterns by Kerievsky. The problem is that refactoring is a way to improve your code and design, but only You can know what you want to achieve, no refactoring tool can do it for you.

My point is that best way to learn refactoring is to study examples, not to follow some stupid/simple tools, because they wont teach you any sophisticated refactoring nor they will tell you if you have refactoring that compose well with you code.

PS Read Fowler "Refactoring" and Kerievsky "Refactoring to design Patterns" those books are must read when learning refactoring. And they mention simple way to checking if refactoring is needed (smells).

Also consider TDD as good way to ensure that your refs are safe and do not break your code. Beck "Test-Driven Development by example" is a good book to start with. And Python have PyUnit for TDD.

przemo_li