Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Refactoring 101

54134c841d22c77be422a8bba5560761?s=47 Josh Ghent
September 06, 2018

Refactoring 101


Josh Ghent

September 06, 2018


  1. Refactoring 101

  2. Hi! cloudcall.com + we're hiring! Josh Ghent @joshghent

  3. •Reduced bugs •Improved test coverage •Quicker development •Improved maintainability •Reduced

    chance of security issues
  4. Always code as if the person who ends up maintaining

    your code is a violent psychopath who knows where you live. - Code for the Maintainer
  5. How do we know What to refactor? Doesn't follow design

    principles Breaking constantly Long on-boarding times Broken tests Outdated Documentation Long classes Badly named routes Inefficient code Outdate dependancies
  6. Lenny Long Functions Annabel the automator Dave the documenter

  7. Original Code

  8. Lenny Long Functions

  9. Encapsulate the logic

  10. None
  11. What can we learn? •Avoid data types in function names

    or variables •Encapsulate logic in sensible chunks •Name functions by their use rather than their description •Follow the single responsibility principle and abstract code where possible
  12. Dave the documenter

  13. Documentation is the Door

  14. @use JSDoc

  15. Comments defining intent

  16. API Swagger

  17. What can we learn? •Explain the HOW and WHY in

    code comments •Good documentation encourages developers to use your library or API •Use simple english for accessibility •Use Swagger for API documentation
  18. Annabel the automator

  19. https://artillery.io Test

  20. Describe each method in your class

  21. nyc --check-coverage --lines 95 npm test Code Coverage github.com/istanbuljs/nyc

  22. Recap • Business advantages of refactoring - reduced cost to

    develop features, less bugs • Developer advantages - speed up development • How to identify code to refactor - code smells, outdated documentation or dependancies • Three ways to refactor code - document, test and abstract
  23. talk.end(); blog.joshghent.com github.com/joshghent/talks