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

Getting a Handle on Legacy Code

Getting a Handle on Legacy Code

We all run into legacy code. Sometimes, we even write it ourselves. Working with legacy code can be a daunting challenge, but there are ways to tackle it without taking on the risk of a full rewrite.

There is a deep satisfaction that comes from conquering a nasty piece of legacy code. The ability to achieve this goal depends on both testing and refactoring.

We'll learn how baby-step refactoring techniques lead to a better understanding of the code and a high-quality design while always keeping the code running.

This is a workshop, so a lot of the material was hands-on practice and not captured in these slides.

Randy Coulman

April 22, 2015
Tweet

More Decks by Randy Coulman

Other Decks in Programming

Transcript

  1. The System • Items have a sell_in value: the number

    of days we have to sell the item • Items have a quality value: how valuable the item is
  2. The System • Items have a sell_in value: the number

    of days we have to sell the item • Items have a quality value: how valuable the item is • At the end of each day our system lowers both values for every item
  3. The Spec: Can We Trust It? • Once the sell-by

    date has passed, quality degrades twice as fast • The quality of an item is never negative • “Aged Brie" actually increases in quality the older it gets • The quality of an item is never more than 50 • "Sulfuras", being a legendary item, never has to be sold or decreases in quality • "Backstage passes", like aged brie, increases in quality as its sell-by date approaches; quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less, but quality drops to 0 after the concert.
  4. Mob Programming • One computer for programming • One driver

    • N navigators and researchers http://mobprogramming.org/mob-programming-basics/
  5. The Legacy Code Algorithm 1. Identify change points 2. Find

    test points 3. Break dependencies 4. Write tests
  6. The Legacy Code Algorithm 1. Identify change points 2. Find

    test points 3. Break dependencies 4. Write tests 5. Make changes and refactor
  7. Cleaning Up the Code The Boy Scout Rule: "Leave the

    campground cleaner than you found it"
  8. Cleaning Up the Code Baby Steps Lots of tiny, safe

    refactorings add up to big changes
  9. Want More? Original Gilded Rose Kata http://craftsmanship.sv.cmu.edu/katas/gilded-rose-kata Gilding the Rose

    Talk at GoGaRuCo 2014 http://confreaks.tv/videos/gogaruco2014-gilding-the-rose-refactoring-legacy-code Code from GoGaRuCo 2014 Talk https://github.com/randycoulman/GildedRose