How to refactor code without IDE functionality (in Vim or TextMate)?
I wonder how do programmers refactor code that is written in languages like Ruby, Python?
Assuming yo开发者_开发问答u get code after a 'previous' guy—so you cannot be sure about quality of tests and their coverage.
Do you use any specific approach?
Without an IDE, you will have to take smaller steps, well protected by comprehensive unit tests. Martin Fowler's Refactoring, written before all the software tools were available, is a pretty good guide to how to refactor safely. You take small steps, checking all along that you're not breaking anything, frequently leaving original code in place until the replacement has been completed. It's tedious but doable.
To refactor code in Python, you can use RopeVim.
in vim
you can use the following command to search for things:
/spock
and get all instances of spock by pressing n
to cycle through the file.
To search and replace, you can use this:
:%s/spock/kirk/g
which will replace all instances of spock with kirk. Vim has some pretty powerful stuff, but you can also use find/sed/grep to do entire directories or projects.
Good luck!
精彩评论