Tech Skills that Matter: Legacy Code

Daniel Prager
EverestEngineering
Published in
3 min readOct 8, 2023

In mid-September Everest Engineering hosted an all-day in-person workshop introducing foundational techniques for refactoring Legacy Code, sometimes defined as profitable code that you are afraid to change.

Pair programming, Trio programming, even some Mob programming

The focus of the day was to address the question, “How do you rapidly set-up a quick and dirty, good enough, automated safety net to refactor legacy code?”

As with Tech Skills that Matter: Pair Programming and Test-Driven Development the day was highly interactive (and fun!) and enabled participants to learn through pairing (and trio-ing), repetition, and a series of carefully crafted challenges.

By the end of the day, participants were having fun, and approaching their refactoring “with confidence, rather than fear”, safe in the knowledge that they had built an automated safety net to alert them to unforeseen breakages — which in the real world can bring down major systems with potentially explosive consequences.

“I loved the step-by-step, hands-on approach to learning new concepts. Pairing during each session also allowed me to consolidate my understanding as I went along.” — Katherine, Quality Coach

A memorable comment on the day reflected the emphasis on building real understanding of complex (and often flawed) business rules:

“It works and passes the test, but I don’t understand why!” — a participant

The approach we took was to build a golden master test, and use it to safely refactor some really bad code, gradually cleaning up the spaghetti and modularising sufficiently to introduce more localised automated unit tests, before proceeding to bug fixes and new features.

The most striking comment of the day was when a participant told the story of how he spent a few years writing software for some tricky hardware, and how if he had been familiar with this particular technique, it might well have saved months if not years of effort!

Caveat: Golden master technique is not the only technique you need to wrestle with the complexity of wrangling legacy code, but it is the best one to learn first. [Then go learn others!]

The day’s learning format was based on the highly interactive Legacy Code Retreat.

In successive one hour sprints (fast, right!), pairs and trios of participants undertook a series of challenges to systematically tame the evil code-base:

  1. Built their own Golden Master test and reviewed the code
  2. Refactored to reduce duplication — undoing previous cut-and-pasting
  3. Refactored to improve names — increasing clarity of the code and making it more self-documenting
  4. Extracted pure functions, added better classes, and identified and fixed bugs

Much of this approach was informed by a higher level strategy of refactoring the code towards Simple Design, which exhibits four properties:

  1. Passes its tests (and ensure sufficient automated tests)
  2. Minimises duplication
  3. Maximises clarity
  4. Has fewer elements

Participants came from a variety of organisations: Catch, CultureAmp, Education Horizons, Our Community, Target, and of course, Everest Engineering.

Participating organisations

To find out more about future editions of this workshop and other technical public or in-house workshops, you can sign up to our newsletter, and read more blog posts at everest.engineering/academy.html

--

--