Skip to content

Instantly share code, notes, and snippets.

@campezzi
Last active November 8, 2019 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save campezzi/e9a0360ba421d9420f57220f11e2ef1a to your computer and use it in GitHub Desktop.
Save campezzi/e9a0360ba421d9420f57220f11e2ef1a to your computer and use it in GitHub Desktop.
Refactoring
  • About me
  • The world's fastest explanation of refactoring
  • Some examples of refactoring from real-life applications
  • Hairier examples of refactoring from real-life applications
  • My refactoring algorithm
  • Open mic

So, you want to refactor some code. Here's how I do it.

  • Do you really want to refactor? Measure pros and cons. Sometimes it's OK to leave it for later.
  • Have a good sense of what you want to do - extract methods, create classes, apply a pattern...
    • Refactoring Guru may give you some ideas
  • Make sure you understand what the code currently does
    • Tests are the best source of information
    • If the tests are heavily tied to the implementation, go cry in a corner somewhere. Then change them to verify a behaviour instead.
  • Add any missing tests to ensure the current behaviour is maintained
    • What if the current behaviour is wrong?
  • Apply your refactoring
  • Run tests until they're all passing
  • Repeat until you're satisfied with your code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment