1 of 17

Nurturing a “Legacy” Code Base

Karen Tracey

DjangoCon US

October 2022

2 of 17

Prelude

3 of 17

Prelude Credit

  • Addy Osmani (@addyosmani) tweet Sept 10
  • “Be careful with legacy code :)”
  • https://twitter.com/addyosmani/status/1568693483845877760
  • 4.5K retweets, 21.5K likes
  • Lots of engagement

4 of 17

Talk Outline

  • What is “legacy” code?
  • Assessing whether to evolve or rebuild
  • Nurturing steps
    • Pre-reqs
    • Easy wins
    • Going deeper

5 of 17

An

Image of “Legacy” Code

By Unknown medieval artist - British Library BL blog, Public Domain, https://commons.wikimedia.org/w/index.php?curid=18087441

6 of 17

What is “legacy” code?

  • Code with (dark?) history
    • Been out of “building” phase a while
    • Current devs may have little/no familiarity with it
  • Follows foreign/outmoded conventions
  • Usually running in production
    • Increases risk for making changes

7 of 17

By Rebuilding Woodstock by Graham Horn, CC BY-SA 2.0, https://commons.wikimedia.org/w/index.php?curid=116667824

An Image of Working On “Legacy” Code

8 of 17

Evolve or start over?

  • Does current code meet current requirements?
  • Frequency/severity of production issues?
  • How healthy are dependencies?

9 of 17

Nurturing

10 of 17

Nurturing pre-requisites

  • Tests: automated and “good”
    • Allows high confidence in changes
    • Ideally, keep increasing coverage
  • Get to supported dependency levels
    • Working on an upgrade a great way to learn
    • Helps reduce outmoded feel

11 of 17

Easy Wins

12 of 17

Nurturing easy wins

  • Black for code formatting
  • Pre-commit for cross-team consistency
  • Linter suggestions for improvement
    • E.g. interpolation -> f-strings
    • Can be done incrementally
    • Possibly could be automated?

13 of 17

Long Term

By H. Zell - Own work, CC BY-SA 3.0, https://commons.wikimedia.org/w/index.php?curid=50453304

14 of 17

Long-term nurturing

  • Goal: devs understand the story of the code
    • Able to determine why a change was made
    • Commit messages can help
    • Issue tracker also key
    • Documentation in repo can be helpful
  • Culture of leaving clues for the future
  • Current investment, future payoff

15 of 17

16 of 17

Summary

  • “Legacy” code value often underestimated
  • Unfamiliarity leads to discomfort and fear
  • Use quick wins to reduce friction
  • Longer term culture adjustments
    • Value time spent recording “why”
    • Value digging deep to understand origin story

17 of 17

Nurtured “Legacy” Code Base

Tim Burkitt, Public domain, via Wikimedia Commons