Duplicated Code
One of the first principles we’re taught as developers: Don’t Repeat Yourself
Symptoms
- You find yourself copy and pasting code from one place to another.
- Shotgun Surgery⭐ occurs when changes to your application require the same small edits in multiple places.
Solutions
- Extract Method⭐ for duplicated code in the same file.
- Extract Class⭐ for duplicated code across multiple files.
- Extract Partial for duplicated view and template code.
- Replace Conditional with Polymorphism for duplicated conditional logic.
- Replace Conditional with Null Object to remove duplicated checks for
nil
value.