Xtreme Programming
Refractor when:β
- You see a bug
- When you add functions
Rule of Threeβ
- Three strikes and you refractor - Martin Fowler
Two Hats - try to keep them seperate
- Add function
- Refractor code
*What to tell the manager? Donβt Computer Science is the discipline that believes all problems can be solved with one more layer of indirection. βDennis DeBruler
Code Smells
- Duplicated Code
- Long Method
- Extract to method
- Large Class
- With too many instance variables
- Extract to subclass
- Long Parameter List
- introduce parameter Object
- Divergent changes - when you need to change multiple things in order to do one thing
- Extract to class
- Shotgun Surgery - when you have to copy paste to a lot of places (opposite of divergent changes)
- Extract method
- Inline classes
- Feature Envy - one class is more concerned on another classes
- Move method
- Primitive obsession - always using primitive types when objects would make more sense, for example money
- Extract to object
- Switch statements - usually signify polymorphism is needed
- Lazy class - classes that doesnβt do much should be removed
- Speculative generality - methods/functions that are not really important and more on βsomeday we will use this"
- Temporary fields
- Middle man
- Data classes - that only have setter and getter are pretty useless - try to move methods that are related to this object in
- Comments
- Inappropriate intimacy
- Message chains
- Refused bequest
- Incomplete Library class
- Alternative classes with different interfaces