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

Le projet legacy, quelles stratégies pour s'en sortir ? – Software Crafts·wo·manship Rennes juin 2021

Le projet legacy, quelles stratégies pour s'en sortir ? – Software Crafts·wo·manship Rennes juin 2021

Arnaud LEMAIRE

June 17, 2021
Tweet

More Decks by Arnaud LEMAIRE

Other Decks in Programming

Transcript

  1. What is Legacy Code ?
    De
    fi
    nition

    View full-size slide

  2. A code


    you want to change,


    that no one understands


    but still provides value.
    De
    fi
    nition

    View full-size slide

  3. A code without
    predictability
    De
    fi
    nition

    View full-size slide

  4. A code without
    predictability
    De
    fi
    nition
    Developers have no idea how long a
    change can take
    01.
    02. There is no correlation between the
    business and the technical complexity
    03. You don’t know when something will
    break

    View full-size slide

  5. A code with no test
    De
    fi
    nition

    View full-size slide

  6. A code with no test
    De
    fi
    nition
    « Most of the fear involved in making changes to
    large code bases is fear of introducing subtle bugs;
    fear of changing things inadvertently.


    Without test, you just don’t know whether things are
    getting better or worse. »
    — Michael Feathers

    View full-size slide

  7. An inverse problem
    De
    fi
    nition

    View full-size slide

  8. An inverse problem
    De
    fi
    nition
    Observations
    Causes
    Forward problem
    Inverse problem

    View full-size slide

  9. An inverse problem
    De
    fi
    nition

    View full-size slide

  10. Hello,


    I work in the
    fi
    nance industry
    at Sunday.app.


    My name is Arnaud LEMAIRE,


    And my twitter handle is
    @lilobase
    Who am I?

    View full-size slide

  11. This talk is focused on
    strategic considerations
    and not tactical ones
    Disclaimer

    View full-size slide

  12. A natural process
    Why does it appear?

    View full-size slide

  13. A natural process
    Why does it appear?
    Add lines of code
    More complexity
    Increase in


    software entropy
    Legacy


    Code

    View full-size slide

  14. You need to let your
    software die*
    A natural process that


    cannot be stopped

    View full-size slide

  15. You need to let your
    software die*
    * a part of your software
    01.
    02. Without bringing the remaining
    parts with it
    03. Optimize your software for
    replacement
    A natural process that


    cannot be stopped

    View full-size slide

  16. That can be speeded up
    or slowed down
    Why does it appear?

    View full-size slide

  17. That can be speeded up
    or slowed down
    Why does it appear?
    Refactoring helps to keep
    complexity under control
    01.
    02. A good software design is critical in the
    long term
    03. Technical debt ≠ legacy software,
    but it can accelerate the process

    View full-size slide

  18. What do we
    do now ?

    View full-size slide

  19. You need to have
    empathy, and take the
    time to understand the
    project's history
    What do we do now ?

    View full-size slide

  20. Strategies


    at the code level
    Legacy Code

    View full-size slide

  21. Would you rather go to the
    dentist twice a year or
    brush your teeth every day?
    When to refactor

    View full-size slide

  22. When to refactor
    Always leave the
    campground cleaner
    than you found it.

    View full-size slide

  23. Always leave the
    campground cleaner
    than you found it.
    When to refactor
    This is the « boy scout rule »
    01.
    03. When you found a bug,
    fi
    rst write a
    test that triggers it, then
    fi
    x it.
    04. Beware of the broken windows
    syndrome
    Developing a new feature and
    refactoring doesn’t mix well!
    02.

    View full-size slide

  24. Culture emerge from
    practices, not the other
    way around.
    When to refactor

    View full-size slide

  25. Stop the weekly
    technical debt
    repayment session
    When to refactor

    View full-size slide

  26. Stop the weekly
    technical debt
    repayment session
    When to refactor
    The « We’ll
    fi
    x it later » syndrome
    01.
    02. The same cause always produces
    the same effect
    Instead provide a learning time, so
    you stop writing legacy code
    03.

    View full-size slide

  27. Avoid the big bang refactoring

    View full-size slide

  28. The mikado™ method
    How to refactor

    View full-size slide

  29. The mikado™ method
    How to refactor
    Undo when an
    experiment fail

    View full-size slide

  30. The golden master Testing
    How to refactor

    View full-size slide

  31. The golden master Testing
    « In nearly every legacy system, what the system
    does is more important that what it’s supposed to
    do. »
    — Michael Feathers
    How to refactor

    View full-size slide

  32. The golden master Testing
    « A Gold Master test is a regression test for
    complex, untested systems that asserts a
    consistent macro-level behavior. »
    — Jake Worth
    How to refactor

    View full-size slide

  33. The Hotspot™ method
    How to refactor

    View full-size slide

  34. The Hotspot™ method
    How to refactor

    View full-size slide

  35. The Hotspot™ method
    How to refactor

    View full-size slide

  36. The Hotspot™ method
    How to refactor

    View full-size slide

  37. Strategies


    at the system level
    Legacy system

    View full-size slide

  38. Refactoring ?
    How to tackle it?

    View full-size slide

  39. Refactoring ?
    How to tackle it?

    View full-size slide

  40. Rewrite ?
    How to tackle it?

    View full-size slide

  41. Rewrite ?
    How to tackle it?

    View full-size slide

  42. The Ship of Theseus strategy
    How to tackle it?

    View full-size slide

  43. The Ship of Theseus strategy
    How to tackle it?

    View full-size slide

  44. Ask your business to help you
    mapping your (business) domain
    01.
    Invoice
    Generation
    Invoicing
    Car rental

    View full-size slide

  45. Ask them to tag where there is
    room for improvement.
    02.
    Invoice
    Generation
    Invoicing
    Car rental

    View full-size slide

  46. Select a tagged support service
    with few dependencies
    03.
    Invoice
    Generation
    Invoicing

    View full-size slide

  47. Rewrite it…
    04.
    Invoice
    Generation
    Invoicing
    New invoice
    Generation

    View full-size slide

  48. And put an anti-corruption layer
    to prevent legacy leakage
    05.
    Invoicing
    New invoice
    Generation
    Legacy API


    Legacy Database
    New Api
    ACL

    View full-size slide

  49. The Anti-Corruption
    Layer
    Anti-Corrupution Layer
    The Green
    fi
    eld code must not call
    directly the Legacy code
    01.
    02. The Legacy code must not call
    directly the Green
    fi
    eld code
    03. Even through the persistence system:
    database or event/message bus

    View full-size slide

  50. Invoicing
    New invoice
    Generation
    Legacy DB Event bus
    Hidden dependencies

    View full-size slide

  51. Invoicing
    New invoice
    Generation
    Legacy DB Event bus

    View full-size slide

  52. Our system Vendor API
    ACL
    An anti-corruption layer can also protect
    us from the outside world

    View full-size slide

  53. Replace the old legacy system
    06.
    Invoicing
    Invoice
    Generation
    New invoice
    Generation

    View full-size slide

  54. Repeat
    07.
    Invoice
    Generation
    Invoicing
    Car rental

    View full-size slide

  55. Until you can reach the core
    08.
    Invoice
    Generation
    Invoicing
    Car rental

    View full-size slide

  56. The Ship of Theseus
    strategy also known as the
    Strangler pattern
    How to tackle it?

    View full-size slide

  57. The Ship of Theseus
    strategy also known as the
    Strangler pattern
    How to tackle it?
    You’ll need to coordinate your
    actions at the system level
    01.
    02. Beware of functional debt
    03. Optimize your new system for
    replacement!

    View full-size slide

  58. What you shouldn’t do
    Some mistakes to avoid

    View full-size slide

  59. Starting from your
    existing system
    Mistakes to avoid

    View full-size slide

  60. Starting from your
    existing system
    Mistakes to avoid

    View full-size slide

  61. Starting by your core
    business
    Mistakes to avoid

    View full-size slide

  62. Starting by your core
    business
    Mistakes to avoid
    Invoice
    Generation
    Invoicing
    Car rental
    !

    View full-size slide

  63. Starting by your core
    business
    Mistakes to avoid
    Too many legacy dependencies
    01.
    02. The developers will need some
    training…

    View full-size slide

  64. Don’t do horizontal
    slicing !
    Mistakes to avoid

    View full-size slide

  65. Don’t do horizontal
    slicing !
    Mistakes to avoid
    UI
    Persistence
    Service
    !

    View full-size slide

  66. Don’t do horizontal
    slicing !
    Mistakes to avoid
    UI
    Persistence
    Service

    View full-size slide

  67. • The Mikado method

    • Software Design X-Rays

    • Working E
    ff
    ectively with Legacy Code

    • Refactoring
    Going further
    Thanks to
    Michael C. Feather, Adam Thornhill, Cyrille Martraire,
    Thomas Pierrain, Martin Fowler, Jean-Baptiste Dusseaut,
    Ola Ellnestam, Daniel Brolund, Adrian Bolboaca

    View full-size slide

  68. Thank you!
    I work in the
    fi
    nance industry
    at Sunday.app.


    My name is Arnaud LEMAIRE,


    And my twitter handle is
    @lilobase

    View full-size slide

  69. Feedbacks ?
    https://roti.express/r/febhha

    View full-size slide