SUBROUTINES FOR MAINTAINABILITY
Breaking a program into well-named subroutines creates modular code. Each subroutine has a single, clear purpose. This makes programs easier to test, debug, and update — you change one subroutine without affecting others.
WITHOUT SUBROUTINES — ONE LONG BLOCK
// 200-line main program with no structure
// Hard to find bugs, hard to update,
// impossible to test individual parts
WITH SUBROUTINES — MODULAR STRUCTURE
displayMenu()
choice ← getValidChoice()
processChoice(choice)
saveResults()
// Each does one thing — easy to test,
// easy to update, easy to read
THREE MAINTAINABILITY TECHNIQUES — SUMMARY
Comments — explain purpose, assumptions, and non-obvious logic
Meaningful names — variables, functions, and procedures that describe what they hold or do
Subroutines — modular blocks with a single purpose, reusable and independently testable