10

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?

3
  • For learning purposes, I'd recommend either refactoring.com or the actual book by Martin Fowler, I don't know of any tool that works exactly like you described :( Commented Apr 26, 2009 at 5:25
  • Do you have a concrete example of the sort of tool you're looking for, that already exists for Python or another programming language? Commented Apr 28, 2009 at 6:56
  • Both pylint and Clone Digger suggest some problematic places by pointing to specific problems in the code, but they do not suggest refactorings themselves. Commented Apr 28, 2009 at 14:43

5 Answers 5

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

You might like Pythoscope, an automatic Python unit test generator, which is supposed to help you bootstrap a unit test suite by dynamically executing code.

Also, have you checked out the rope.contrib.codeassist module? It is supposed to automatically propose and perform refactorings of your source code for you.

Comments

1

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.

1 Comment

Cyclomatic complexity isn't a tool, it's a code metric.
1

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.

Comments

0

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/

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.