Beware of the legacy! The one you inherit and the one you create

47c28f369d87931c0ba1f324e40e8c4e?s=47 Carola Nitz
October 04, 2018

Beware of the legacy! The one you inherit and the one you create

In this talk, we’re going to take a look at what problems we face when working with a legacy code base. We’ll explore and evaluate strategies that help you make changes with confidence and steps you can take to make the person who works with your legacy code not hate you! We show you tricks and tools so that you can find hidden dead code and references and will look at ways how you can work more efficiently with a grown codebase.

47c28f369d87931c0ba1f324e40e8c4e?s=128

Carola Nitz

October 04, 2018
Tweet

Transcript

  1. 3.

    MOTIVATION: ▸ approaches to work with a grown codebase ▸

    create a great legacy yourself ▸ talk about common pitfalls
  2. 5.
  3. 6.

    To me, legacy code is simply code without tests Michael

    C. Feathers, Working Effectively with Legacy Code
  4. 8.
  5. 10.
  6. 11.
  7. 15.
  8. 16.
  9. 17.

    PROJECT SETUP ▸ work with Pullrequests ▸ setup a Continous

    Integration ▸ build all platforms with the lowest supported OS
  10. 18.

    DANGER ▸ Enforce CHANGELOGs ▸ Enforce links to Trello/JIRA in

    PR/MR bodies ▸ Enforce using descriptive labels ▸ Look out for common anti-patterns ▸ Highlight interesting build artifacts ▸ Give specific files extra focus
  11. 19.

    SWIFTLINT ▸ define rules for code style ▸ keeps code

    consistent ▸ restrict functions by number of lines
  12. 23.
  13. 24.

    WHEN A REWRITE IS USEFUL ▸ you overhaul a big

    feature ▸ you switch programming languages
  14. 27.

    IDENTIFYING PLACES FOR CHANGE ▸ find the code piece that

    causes the most pain ▸ that's being touched the most ▸ that causes the most regressions when being changed
  15. 28.
  16. 30.

    BENEFITS OF WRITING TESTS ▸ you think about edgecases ▸

    it gives you confidence when you touch that code ▸ speeds you up because even if you have it just partly tested you know where not to look
  17. 32.
  18. 34.

    SPROUT METHOD & SPROUT CLASS ▸ write new code in

    methods ▸ pass needed parameters ▸ return what needs to be returned
  19. 35.
  20. 36.

    WRAP METHOD & WRAP CLASSES ▸ adds functionality in new

    method ▸ calls the old code or old class
  21. 37.
  22. 40.
  23. 41.

    EXTRACTION METHOD ▸ goal: break up or separate big existing

    functions ▸ identifying well encapsulated blocks
  24. 42.
  25. 43.

    EXTRACTING BOOLS if _repeatMode != VLCRepeatCurrentItem && mediaListCount > 2

    && _shuffleMode { ... } to BOOL canShuffle = _repeatMode != VLCRepeatCurrentItem && mediaListCount > 2; if canShuffle && _shuffleMode { ... }
  26. 44.

    FEATURE FLAGS ▸ Used to turn on new features ▸

    Can be used to switch between new and old implementations
  27. 45.

    FINDING DEAD CODE ▸ Grep is your friend ▸ cocoapods

    not removing references ▸ static analyzer to find code that never gets called
  28. 46.

    SUMMARY: ▸ Automate as much as you can ▸ How

    to incrementally add tests ▸ Add features without piling onto old code ▸ Refactor step by step
  29. 47.
  30. 48.

    Resources: Working Effectively with Legacy Code - Michael Feathers Beyond

    Legacy Code - David Scott Bernstein Refactoring - Kent Beck and Martin Fowler http://samuelmullen.com/articles/legacy_isnt_a_bad_word/ https://www.objc.io/issues/1-view-controllers/lighter-view- controllers/
  31. 49.