Code Maintenance Examples in CS Thinking
Start with the recap, study the fully worked examples, then use the practice problems to check your understanding of Code Maintenance.
This page combines explanation, solved examples, and follow-up practice so you can move from recognition to confident problem-solving in CS Thinking.
Concept Recap
The ongoing process of updating, fixing, and improving software after its initial release to correct bugs, adapt to new requirements, and improve performance.
Software is never 'done.' Like a garden, it needs constant tending โ fixing bugs, updating dependencies, and adapting to changing needs.
Read the full concept explanation โHow to Use These Examples
- Read the first worked example with the solution open so the structure is clear.
- Try the practice problems before revealing each solution.
- Use the related concepts and background knowledge badges if you feel stuck.
What to Focus On
Core idea: Maintenance typically consumes 60-80% of software's total lifetime cost. Writing maintainable code from the start saves enormous effort later.
Common stuck point: Maintenance isn't just fixing bugs โ it includes adapting to new requirements, improving performance, and preventing future problems.
Worked Examples
Example 1
easySolution
- 1 Step 1: If the tax rate changes, you must find and update all 15 occurrences. Missing even one creates a bug.
- 2 Step 2: Fix: define a named constant: CONST TAX_RATE = 0.2. Use TAX_RATE everywhere instead of 0.2.
- 3 Step 3: Now a rate change requires editing only one line. This is the 'magic number' anti-pattern โ unexplained numbers scattered through code.
Answer
Example 2
mediumPractice Problems
Try these problems on your own first, then open the solution to compare your method.
Example 1
mediumExample 2
hardRelated Concepts
Background Knowledge
These ideas may be useful before you work through the harder examples.