liveBook · Manning

Legacy code

As explained in Build High Value Software Systems

Legacy code is existing software that a team inherits and must understand or change, regardless of whether it is still useful and operational.

Legacy code is existing software that lacks enough safety to change confidently. Age and quality are not the test: working systems that deliver value can still be difficult to modify. section 7.0 section 7.1

Before changing an unfamiliar system:

  • Observe runtime behavior with real inputs before relying on code structure or potentially outdated documentation. section 7.1
  • Read tests for clues about intended behavior, then investigate the code where its decisions and constraints are encoded. section 7.1
  • Improve incrementally with safety nets; avoid replacing the whole system in one risky change. section 7.1.1

A payment confirmation mystery

A payment service sends no confirmation for European customers on Tuesday. Runtime evidence reveals that emails are sent only during US business hours—a hidden constraint, not necessarily a bug. section 7.1

Listing 7.1 Before understanding the code, observe it in action
import logging
 
logger = logging.getLogger(__name__)
 
def process_payment(customer, amount, currency):
    logger.info(f"Processing payment: customer={customer.id}, amount={amount}, currency={currency}")
    # ... existing logic ...
    logger.info(f"Payment status: {status}, confirmation_sent={confirmation_sent}")
    logger.info(f"Timezone used: {timezone}, day_of_week: {day_of_week}")

A short logging example shows how to record payment inputs, status, confirmation delivery, and timezone while investigating behavior. section 7.1

Treat change safety as something to build, not a reason to abandon useful software. Characterization tests preserve current behavior, while small improvements help maintain flow. section 7.1.1 section 7.6

How Build High Value Software Systems covers it

How deep it goes
Defines legacy by insufficient change safety and offers investigation and improvement heuristics, without prescribing a full migration implementation.
Examples
Uses a Java payment service whose Tuesday European confirmations expose an undocumented US-business-hours rule.
What you can do after
Diagnose inherited behavior by observing runtime, reading tests, and tracing code; prioritize incremental changes with safety nets.
How it connects
Connects legacy code to Lean, characterization tests, technical debt, YAGNI, and the Strangler Fig pattern.

Also explained in

Compare how 3 books explain legacy code →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build High Value Software Systems. The section links point to the parts of the book it draws on.