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

Refactoring

 Refactoring

A practical example of refactoring a part of the MoJ video hearings service website questionnaire journey.

David Dikman

June 21, 2019
Tweet

More Decks by David Dikman

Other Decks in Programming

Transcript

  1. Refactoring ➔ Not scheduled It’s cleaning up before or better

    yet, after we do something. ➔ Not rewriting We’re moving code, not changing functionality ➔ Iterative Run test. Tinker (move code, rename). Run test. Repeat. ➔ Requires test When you have tests you can refactor without fear.
  2. So we refactor. The first solution worked. It was fine.

    Next time? Probably takes longer, more tests more bugs and harder to do. Let’s clean up! Photo by Emma Matthews on Unsplash
  3. We have one sub-class per textbox choice page, all have

    ~8 tests testing the exact same functionality. Step 1 Find a problem. Here be Duplication.
  4. Break out functionality. Make it reusable. Test it. Step 2

    Duplicate some Break out and generalise Forward/wrap functionality, tests ✓
  5. Remove superfluous code Step 4 Remove duplicate tests. Run tests,

    ✓, coverage 100% PR & run acceptance tests, page still works.
  6. After proving it works. Rinse and repeat. Step 5 Bypass

    base component in other components. Run tests ✓ Check usages. None. Delete. Tests still ✓
  7. Result? A little more code in components, code that actually

    belonged in there. Far fewer classes. No test duplication. Functionality tested once = less maintenance. Decoupling. Same form, different journeys.
  8. Summary 1. We never know how to do it the

    first time, no point trying 2. We make it work instead 3. Then we make it maintainable 4. Then we repeat
  9. Disclaimers and observations • Process a little different from actual

    steps. • Many more iterations than described. • I tried things, redid many times • I did PR early ◦ Runs acceptance tests ◦ Shows complexity/flow ◦ Smaller increments