Refactoring
up: Programming ⚐
Practical refactoring
Practical Refactoring - How to clean code in many small steps
Things to remove:
-
Clutter
- ”Anything in your code that does not add value”
- Redundant comments
- Dead code
- Unneccesary code
- That makes everything else harder to understand.
- ”Anything in your code that does not add value”
-
Complexity
- Bad names
- Long methods
- Every method should fit on a screen
- Find the “seams”1, and break it into new methods
- These should be Methods should state their intent in the name.
- Deep conditionals
- Magic numbers/strings
- Magic numbers, if required, should be in a seperate settings file.
-
Cleverness
- Make it clear. Make it elegant. Make it easy to read. Clever is going to bite you later.
- If it needs a comment, it’s clever.
-
Duplication
- Extract repeated statements into methods
Footnotes
-
Usually curly-braches, like
if
expressions. This is similar to the Extract Conditional Pattern. ↩