Confident refactors

Confident refactors

C74bdcd3fa7c3d3f23290f46430b1463?s=128

Mehdi Lahmam B.

June 19, 2017
Tweet

Transcript

  1. Confident Refactors

  2. Mehdi Lahmam @mehlah

  3. 25kV Rails app, started in Feb 2009 Never rewritten 23k+

    commits from 52 contributors
  4. Ruby is a massively successful language!

  5. Early success Making it easy to make new things

  6. Later success Making it easy to maintain old things

  7. Today, let’s refactor some legacy code

  8. Today, let’s refactor some legacy code

  9. Refactor - verb To change the design of code without

    changing its observable behavior.
  10. Refactor - verb To change in advance of a new

    feature or bug fix, making the job easier.
  11. Today, let’s refactor some legacy code

  12. Legacy - noun Old code.

  13. Legacy - noun Code without tests.

  14. Legacy - noun Code that we don’t like.

  15. Legacy - noun Code we don’t understand well enough
 to

    change confidently.
  16. Today, let’s refactor some legacy code

  17. Refactoring is hard

  18. Refactoring legacy code is very hard

  19. Easy to accidentally break functionality

  20. Legacy refactors feels unsafe

  21. Legacy refactors are hard to sell

  22. Business priority Cost / risks

  23. Business priority Cost / risks New features

  24. Business priority Cost / risks New features Bugs fixes

  25. Business priority Cost / risks New features Bugs fixes Testing

  26. Business priority Cost / risks New features Bug fixes Testing

    Refactoring
  27. Business priority Cost / risks New features Bug fixes Testing

    Refactoring no selling needed easy to sell can often sell very hard to sell
  28. Selling refactoring is hard ⏲ ⛔

  29. Business priority Cost / risks Refactoring

  30. Too much pressure ⏳ ⚒

  31. Refactors are scary

  32. What techniques we have? PDD - Pray Driven Development Fowler’s

    refactoring book Characterization testing A/B testing, experiments
  33. Refactors as surgeries

  34. Refactors as surgeries Requires careful planning Follow a clear process

    Multiple observations Flexible tools Things can get bloody
  35. 1. Plan 2. Cut 3. Record 4. Validate 5. Refactor

    6. Verify 7. Compare 8. Fallback 9. Delete Clear process
  36. None
  37. None
  38. None
  39. Cut

  40. Record

  41. Validate ✅

  42. Refactor <Insert magic here />

  43. Verify

  44. Compare ⚖

  45. Fallback

  46. Delete ✂

  47. We dit it

  48. We dit it Time to celebrate hard