Maintainability: Use of sub programs; Naming conventions; Indentation; Commenting
2.3.1 Defensive Design
Practise exam questionsDefensive Design — Note 3 of 3
Understand why each of the identified maintainability techniques are useful and apply this appropriately
Maintainability refers to how easy it is to understand, update, and fix a program after it has been written. Good maintainability practices include using sub-programs to break code into manageable sections, following clear naming conventions for variables and functions, using proper indentation, and adding comments to explain the code.
totalPrice not tp, position not p.PI = 3.142, MAX_POSITION = 512) so they can be 'updated once and it updates throughout'.#. In OCR Exam Reference Language comments start with //. Comments are ignored when the program runs.# POOR maintainability
x = float(input("Enter value: "))
y = float(input("Enter value: "))
z = x / y
print(z)
# GOOD maintainability
# Calculate speed from distance and time
distance = float(input("Enter distance (m): "))
time = float(input("Enter time (s): "))
speed = distance / time # speed = distance / time
print("Speed: " + str(speed) + " m/s")# This is a comment: Python ignores it when the program runs.
# Use comments to explain WHAT a section does and WHY.
total = 0 # running total of all the scores (an inline comment)Ready to test yourself?
Practise 2.3.1 questionsRevise another OCR GCSE topic: Testing