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


