Refactoring

Why we refactor

  • Makes the code easier to understand
  • It helps us find bugs
  • It prevent spaghet reach a critical point
  • It will be a time saver in the long run

When to refactor

Traditionally we should refactor when the same code is written three times and when it’s startig to become hard to understand. But in this project we’ll do it after every feature added.

Signs of spaghettification

This is what we need to refactor if any of this are true then it’s begging to be refactored:

  • Duplicated code
  • Hard to understand function / variable name
  • Long ass function
  • Long parameter list (unless it’s a constructor)
  • Global data
  • Mutable data
  • Divergent change
  • Repeated Switch
  • Deeply nested loops
  • Large class
  • Comments

To be honest we don’t really need a long list of what to refactor because deep within we already know what’s fucked up and what’s perfectly fine.