Skip to main content

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