You are here
My code refactoring algorithm
Liraz Siri - Mon, 2011/05/02 - 09:26 -
5 comments
You're looking at a block of Python code. It's not immediately obvious what it does. It's sort of a mess and you realize it needs to be refactored. But how? What mental algorithm do you use?
Here's a trick I just figured out how to put into words. You first add comments to your code to make it easier to explain what it's doing in each part. Then you restructure the code until those comments are no longer necessary, using the comments as a guide to creating high level constructs that not only tuck complexity neatly away, they also explain the purpose of the surface.
What tricks do you use?
Comments
Umh, I don't get what you
Umh, I don't get what you mean. If you always chose the right names for indentifiers and care about the common guidelines (not to much identation levels, useful sparse comments, etc) you don't need to refactor code because "readability" problems.
Those are good rules of thumb
Finally somone actually put
Finally somone actually put that in words :)
version control thinking helps
I find it useful to code when you know it is under version control. And you know you will eventually need to read patches and stuff. This makes you write shorter lines, break your expressions into more lines. This improves readability a lot.
Version control essential
Pages
Add new comment