Could another programmer understand your code?
A program may work correctly today, but another programmer might need to fix it or add a new feature later.
A maintainable program is written so that its purpose and structure are easy to understand.
A maintainable program is easy for another programmer to read, understand, test and change safely.
A program may work correctly today, but another programmer might need to fix it or add a new feature later.
A maintainable program is written so that its purpose and structure are easy to understand.
Imagine leaving instructions for another teacher to run your lesson. Notes such as “do the thing” or “use x” would be difficult to follow.
Clear headings, sensible names and organised steps make the instructions usable. Program code works in exactly the same way.
x ← 0 FOR i ← 1 TO 5 x ← x + s[i] NEXT i OUTPUT x
// Calculate the total score TotalScore ← 0 FOR ScoreIndex ← 1 TO 5 TotalScore ← TotalScore + Scores[ScoreIndex] NEXT ScoreIndex OUTPUT TotalScore
The program gives the same output, but the comment and meaningful identifiers reveal its purpose immediately.
// Calculate the average mark Total ← 0 FOR Index ← 1 TO ClassSize Total ← Total + Marks[Index] NEXT Index Average ← Total / ClassSize
# Calculate the average mark
total = 0
for mark in marks:
total += mark
average = total / len(marks)For an explain question, simply writing “use comments” is usually not enough.
Give three techniques and explain how each one improves readability or makes future changes safer.
The explanation must show how the technique helps another programmer maintain the code.