- If you go red, undo
- Only change one line at a time
- Find two strings that are the most alike
- Find the smallest difference
- Make the smallest change that make the tests pass
- Parse: run code, check if errors
- Execute without using result
- Execute using the result
- Delete unused code
Is code open?
Y -> make change
N -> can I make it open?
Y -> make change
N -> Fix easy sin, and start over again, is code open?
- Simple: don't be too clever, "drunk me doesn't understand"
- Green Green Green: lean on green, don't fight red, avoid rabbit holes
- Small easy steps: find most alike, fix the smallest sin, start with small steps instead of trying to fix big complex problems, fix easy things first to make the hard things easy
- Dare to be boring: step by step refactoring recipe can seem so simple it will almost be boring
- Don't abstract prematurely
- Don't plan for unknown future
- Meaningful variable names within the domain help with understanding the domain
- It is almost always 90% maintenance / 10% new code
- Terse is not better
- Try to avoid procedural if/else flow
- SRP: Single Responsibility Principle
- Open/Close
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
Know the code smell => Know the recipe to refactor
Examples of code smells:
- Too many private methods is a code smell that there might be another object hiding in there
- Primitive obsession
- Data clumps
- Duplication
- Classes and methods that do too much
- Methods that return different objects
Boring is better -> identify code shapes -> look for code smells -> principled refactoring