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 Slide

  2. Refactoring stories from the trenches

    View Slide

  3. Beyond process

    View Slide

  4. Legacy code kills agility

    View Slide

  5. What is legacy code?

    View Slide

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

    View Slide

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

    View Slide

  8. Do Product Owners see value in fixing it?

    View Slide

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

    View Slide

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

    View Slide

  11. Development teams are just as guilty

    View Slide

  12. Why improve legacy code?

    View Slide

  13. Craftsmanship
    Professionalism | Clean Code | Right Thing

    View Slide

  14. Quality
    Maintainability and Extensibility

    View Slide

  15. Economics

    View Slide

  16. What is refactoring? What is our goal?

    View Slide

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

    View Slide

  18. Maximise Safety

    View Slide

  19. Construction Refactoring

    View Slide

  20. Structure
    Behaviour
    vs.

    View Slide

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

    View Slide

  22. Code changes

    View Slide

  23. Cleaning up as we go

    View Slide

  24. A lot is written about this

    View Slide

  25. How would you approach it?

    View Slide

  26. Golden Master
    Golden Master

    View Slide

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

    View Slide

  28. Frequent small commits

    View Slide

  29. Fix bugs separately

    View Slide

  30. Don Roberts’ Rule of Three

    View Slide

  31. Integrated tests are a scam

    View Slide

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

    View Slide

  33. Solution-wide refactoring

    View Slide

  34. Handling major problems

    View Slide

  35. From the trenches

    View Slide

  36. Shanty Town
    What if this is the campsite?

    View Slide

  37. We decided to refactor…

    View Slide

  38. 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 Slide

  39. Shouldn’t we just rewrite?

    View Slide

  40. View Slide

  41. 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 Slide

  42. 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 Slide

  43. Small incremental changes
    Less than 5 days

    View Slide

  44. Team structure

    View Slide

  45. Team structure

    View Slide

  46. Cohesion and Coupling applies to teams

    View Slide

  47. In closing

    View Slide

  48. Handling major problems

    View Slide

  49. Cleaning up as we go

    View Slide

  50. Economics

    View Slide

  51. [email protected] @martincronje

    View Slide