Refactoring and Legacy Code

Installation
SKILL.md

Refactoring and Legacy Code

Stance

Legacy code is code without tests that works and pays the bills. The goal is safe change, not beauty. Never mix refactoring and behavior change in one commit.

Workflow

  1. Pin the behavior. Write characterization tests around the area you are about to touch (input → observed output, even if the output looks wrong). If untestable, find a seam.
  2. Find seams: where can you substitute a dependency without editing callers? Introduce one (extract interface, inject clock/HTTP client, wrap a static call).
  3. Refactor in tiny steps, running tests after each: rename, extract function, move, inline, replace conditional with polymorphism.
  4. Measure the target improvement: cyclomatic complexity, change frequency × complexity (hotspots), duplication, build time, test coverage of the touched path.
  5. Only then change behavior, with the new tests proving both old and new expectations.

Strangler pattern (replace a subsystem)

Installs
–
First Seen
–