Maintainability

If you leave the company, the next developer must be able to read and fix your code without breaking the system. This relies on the four pillars of Maintainability.

The Four Methods

1. Comments

Lines completely ignored by the computer. They explain the code's purpose in plain English so other humans know what it does.

2. Indentation

Visually grouping code blocks. It makes it instantly obvious which lines belong inside a specific IF statement or Loop.

3. Naming Conventions

Using descriptive identifiers. A variable named totalScore makes sense; a variable named x is confusing.

4. Subprogrammes

Breaking a giant 10,000 line programme into smaller, modular functions. If the 'Login' breaks, you know exactly which module to check.

Examiner's Eye - The 'Easier to Read' Trap

If an exam simply asks "Why makes code maintainable?", you will score zero marks for answering "It makes it easier to read". The examiner knows that! You MUST name a specific technique, e.g. "By using meaningful variable names, other programmers can identify exactly what data is being held.".

The Clean Code Transformer

The code block below is "Spaghetti Code". It works, but it breaks every maintainability rule. Trigger the four toggle switches to automatically format the code.

Indentation
Naming
Comments
Subprogrammes
# -- Subprogramme to process payments -- x = input() # Gets customer card number IF x > 100 THEN y = x * 0.8 # Applies 20% loyalty discount print(y) ELSE print("No discount")

STATUS: Messy Spaghetti Code

Check Your Understanding

1. Using descriptive variable names (e.g. `finalScore` instead of `fs`) is primarily best practice because:

2. I have a 5,000 line programme. The 'Checkout' system has broken. I have to read through all 5,000 lines to find the math logic. What maintainability method should I have used?

Written Exam Scenario (AO2/AO3)

Stretch (Grade 9)

"The following Python pseudocode is difficult to maintain.
p = float(input())
if p > 0:
t = p * 1.2
print(t)

Rewrite the entire block of code applying three specific maintainability strategies to secure full marks." (4 marks)