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

Rescuing Legacy Software from Impending Doom. Refactoring Stories from the Trenches

Rescuing Legacy Software from Impending Doom. Refactoring Stories from the Trenches

Dealing with an ageing code base is one of the hardest software engineering problems we face today. It is critical to solve this problem on the road to agility. In the past, software rewrites was standard practice when a company wanted to get rid of legacy software. Modern development practices and techniques has made refactoring a very popular first choice for software teams. In our experience we’ve seen how different teams attempted to systemically refactor their code with varying levels of success.

We will share the experiences of two software start-ups and a mid-size organisation. The speaker will explore case studies to guide attendees towards successful refactoring.

Topics covered in this talk will include
- effective refactoring methods (checklists),
- using test-driven development to support refactoring,
- when to do aggressive refactoring,
- common pitfalls and,
- classifications of technical debt to manage recovery.

We will also look at refactoring beyond the context of code, such as redesigning solutions and teams to improve agility.

Martin Cronjé

November 04, 2014
Tweet

More Decks by Martin Cronjé

Other Decks in Programming

Transcript

  1. Rescuing legacy software from impending doom
    [email protected] @martincronje

    View full-size slide

  2. Refactoring stories from the trenches

    View full-size slide

  3. Beyond process

    View full-size slide

  4. Legacy code kills agility

    View full-size slide

  5. What is legacy code?

    View full-size slide

  6. “legacy code is simply code
    without tests.”
    Michael Feathers

    View full-size slide

  7. “Legacy code is valuable code
    that we feel afraid to change.”
    J.B. Rainsberger

    View full-size slide

  8. Do Product Owners see value in fixing it?

    View full-size slide

  9. Typically they say…
    Not enough time
    We cannot afford it
    Business will close-down
    Just one more feature

    View full-size slide

  10. So I went to speak to them...

    View full-size slide

  11. Development teams are just as guilty

    View full-size slide

  12. Why improve legacy code?

    View full-size slide

  13. Craftsmanship
    Professionalism | Clean Code | Right Thing

    View full-size slide

  14. Quality
    Maintainability and Extensibility

    View full-size slide

  15. What is refactoring? What is our goal?

    View full-size slide

  16. Improve the design of code to
    make it easier to work with.
    Joshua Kerievsky

    View full-size slide

  17. Maximise Safety

    View full-size slide

  18. Construction Refactoring

    View full-size slide

  19. Structure
    Behaviour
    vs.

    View full-size slide

  20. New code Code changes Solution wide
    TDD Refactoring Litter-Pickup Refactoring
    Comprehension Refactoring
    Preparatory Refactoring
    Planned Refactoring
    Long-Term Refactoring
    Refactoring workflows

    View full-size slide

  21. Code changes

    View full-size slide

  22. Cleaning up as we go

    View full-size slide

  23. A lot is written about this

    View full-size slide

  24. How would you approach it?

    View full-size slide

  25. Golden Master
    Golden Master

    View full-size slide

  26. Refactoring Activities
    Standards
    Readability
    Comprehension and Intent
    Separate concerns (Coupling)
    Consolidate responsibilities (Cohesion)
    Increased risk

    View full-size slide

  27. Frequent small commits

    View full-size slide

  28. Fix bugs separately

    View full-size slide

  29. Don Roberts’ Rule of Three

    View full-size slide

  30. Integrated tests are a scam

    View full-size slide

  31. Run simulations!
    Tracer bullets..
    Tracer bullet refactoring

    View full-size slide

  32. Solution-wide refactoring

    View full-size slide

  33. Handling major problems

    View full-size slide

  34. From the trenches

    View full-size slide

  35. Shanty Town
    What if this is the campsite?

    View full-size slide

  36. We decided to refactor…

    View full-size slide

  37. Problems in a real system
    •  Hardcoding everywhere
    •  Half-baked refactoring
    •  Unused code
    •  Duplication of code
    •  Code rewritten due to fear of extension
    •  No separation of concerns
    •  Namespaces not controlled
    •  Inconsistent external dependencies
    •  … and many more

    View full-size slide

  38. Shouldn’t we just rewrite?

    View full-size slide

  39. Backlog
    •  Consolidate repositories
    •  Standards
    •  Clean-code across solution
    •  Create scaffolding packages
    •  Get things that change together to live together
    •  Undo partial refactoring attempts
    •  Breaking up the silo

    View full-size slide

  40. Activities
    •  Initiatives added to product backlog
    •  Public legacy code reviews
    •  Refactoring simulations on extreme messes
    •  20-40% allocation to fix the code
    •  Hack days to address specific problems

    View full-size slide

  41. Small incremental changes
    Less than 5 days

    View full-size slide

  42. Team structure

    View full-size slide

  43. Team structure

    View full-size slide

  44. Cohesion and Coupling applies to teams

    View full-size slide

  45. Handling major problems

    View full-size slide

  46. Cleaning up as we go

    View full-size slide