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

Confident refactors

Confident refactors

Mehdi Lahmam B.

June 19, 2017
Tweet

More Decks by Mehdi Lahmam B.

Other Decks in Technology

Transcript

  1. Confident Refactors

    View full-size slide

  2. Mehdi Lahmam
    @mehlah

    View full-size slide

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

    View full-size slide

  4. Ruby is a massively
    successful language!

    View full-size slide

  5. Early success
    Making it easy to make new things

    View full-size slide

  6. Later success
    Making it easy to maintain old things

    View full-size slide

  7. Today, let’s refactor
    some legacy code

    View full-size slide

  8. Today, let’s refactor
    some legacy code

    View full-size slide

  9. Refactor - verb
    To change the design of code
    without changing its observable behavior.

    View full-size slide

  10. Refactor - verb
    To change in advance of a new feature
    or bug fix, making the job easier.

    View full-size slide

  11. Today, let’s refactor
    some legacy code

    View full-size slide

  12. Legacy - noun
    Old code.

    View full-size slide

  13. Legacy - noun
    Code without tests.

    View full-size slide

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

    View full-size slide

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

    to change confidently.

    View full-size slide

  16. Today, let’s refactor
    some legacy code

    View full-size slide

  17. Refactoring is hard

    View full-size slide

  18. Refactoring legacy code
    is very hard

    View full-size slide

  19. Easy to accidentally
    break functionality

    View full-size slide

  20. Legacy refactors
    feels unsafe

    View full-size slide

  21. Legacy refactors
    are hard to sell

    View full-size slide

  22. Business priority
    Cost / risks

    View full-size slide

  23. Business priority
    Cost / risks
    New features

    View full-size slide

  24. Business priority
    Cost / risks
    New features
    Bugs fixes

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  27. Business priority
    Cost / risks
    New features
    Bug fixes
    Testing Refactoring
    no selling
    needed
    easy to sell
    can often sell
    very hard to sell

    View full-size slide

  28. Selling refactoring is hard
    ⏲ ⛔

    View full-size slide

  29. Business priority
    Cost / risks
    Refactoring

    View full-size slide

  30. Too much pressure
    ⏳ ⚒

    View full-size slide

  31. Refactors are scary

    View full-size slide

  32. What techniques we have?
    PDD - Pray Driven Development
    Fowler’s refactoring book
    Characterization testing
    A/B testing, experiments

    View full-size slide

  33. Refactors as surgeries

    View full-size slide

  34. Refactors as surgeries
    Requires careful planning
    Follow a clear process
    Multiple observations
    Flexible tools
    Things can get bloody

    View full-size slide

  35. 1. Plan
    2. Cut
    3. Record
    4. Validate
    5. Refactor
    6. Verify
    7. Compare
    8. Fallback
    9. Delete
    Clear process

    View full-size slide

  36. Validate ✅

    View full-size slide

  37. We dit it
    Time to celebrate hard

    View full-size slide