Repaso
Español
Design & PracticesAdvancedDP-28

You inherit a 2,000-line legacy module with no tests and must change it. How do you proceed safely?

Answer

  • Read and map the behavior; find the area you must change and its seams.
  • Add characterization tests that capture current behavior (even strange behavior) around that area.
  • Refactor in small steps that do not change behavior: extract functions, rename, inject dependencies.
  • Make the change with tests in place; consider a feature flag.
  • For big rewrites use the Strangler Fig pattern: move pieces to new code gradually.
  • Ship in small increments, monitor, keep commits reviewable.

Key terms

Practice this question in Repaso