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

Beware of the legacy! The one you inherit and t...

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.

Carola Nitz

October 04, 2018
Tweet

More Decks by Carola Nitz

Other Decks in Technology

Transcript

  1. MOTIVATION: ▸ approaches to work with a grown codebase ▸

    create a great legacy yourself ▸ talk about common pitfalls
  2. To me, legacy code is simply code without tests Michael

    C. Feathers, Working Effectively with Legacy Code
  3. PROJECT SETUP ▸ work with Pullrequests ▸ setup a Continous

    Integration ▸ build all platforms with the lowest supported OS
  4. 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
  5. SWIFTLINT ▸ define rules for code style ▸ keeps code

    consistent ▸ restrict functions by number of lines
  6. WHEN A REWRITE IS USEFUL ▸ you overhaul a big

    feature ▸ you switch programming languages
  7. 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
  8. 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
  9. SPROUT METHOD & SPROUT CLASS ▸ write new code in

    methods ▸ pass needed parameters ▸ return what needs to be returned
  10. WRAP METHOD & WRAP CLASSES ▸ adds functionality in new

    method ▸ calls the old code or old class
  11. EXTRACTION METHOD ▸ goal: break up or separate big existing

    functions ▸ identifying well encapsulated blocks
  12. EXTRACTING BOOLS if _repeatMode != VLCRepeatCurrentItem && mediaListCount > 2

    && _shuffleMode { ... } to BOOL canShuffle = _repeatMode != VLCRepeatCurrentItem && mediaListCount > 2; if canShuffle && _shuffleMode { ... }
  13. FEATURE FLAGS ▸ Used to turn on new features ▸

    Can be used to switch between new and old implementations
  14. FINDING DEAD CODE ▸ Grep is your friend ▸ cocoapods

    not removing references ▸ static analyzer to find code that never gets called
  15. SUMMARY: ▸ Automate as much as you can ▸ How

    to incrementally add tests ▸ Add features without piling onto old code ▸ Refactor step by step
  16. 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/