Programs are read far more often than they are written. Someone, often you, will have to fix or update your code months later. Learn the techniques the syllabus expects: meaningful identifiers, comments, constants, and procedures and functions.
A maintainable program is easy for another programmer to understand, correct and update. Use meaningful identifiers for variables, constants, arrays, procedures and functions, so each name says what it holds or does. Add comments (starting with // in pseudocode) to explain the purpose of sections of code; the computer ignores them. Use constants for fixed values and procedures and functions to split the program into named, reusable parts.
Fig. 1: both programs do the same job, but only one explains itself
Section 01
Meaningful identifiers.
Compare the two versions of the same algorithm. The second needs no explanation: the names tell you what each value is.
X ← 0
FOR I ← 1 TO 30
INPUT Y
X ← X + Y
NEXT I
OUTPUT X / 30
// Works out the average mark for one class
CONSTANT ClassSize ← 30
DECLARE TotalMark : INTEGER
DECLARE Mark : INTEGER
DECLARE Student : INTEGER
TotalMark ← 0
FOR Student ← 1 TO ClassSize
INPUT Mark
TotalMark ← TotalMark + Mark
NEXT Student
OUTPUT "Average mark: ", TotalMark / ClassSize
Describe the data: TotalMark, StudentNames, CalculateTax, not X, A2 or Thing.
Pascal case: capital letter at the start of each word, e.g. NumberOfPlayers.
Rules: letters and digits only, start with a letter, no spaces or underscores, never a keyword. Single letters are fine only where conventional, such as i and j for array indexes.
Examiner trap
"Use good variable names" is too vague for a mark. Say meaningful identifiers and explain the benefit: another programmer can see what each variable stores, so the code is easier to understand and update.
Section 02
Comments.
A comment is a note for human readers. In pseudocode it starts with two forward slashes and continues to the end of the line. It usually goes on its own line above the code it describes.
// Validate the age: it must be from 11 to 18
REPEAT
INPUT Age
UNTIL Age >= 11 AND Age <= 18
Discount ← Price * 0.1 // 10% discount for students
The same idea in Python (for comparison only: the exam uses pseudocode)
# Python comments start with a hash
discount = price * 0.1 # 10% discount for students
Worked example Useful or not?
Which comment is more useful above the line Count ← Count + 1 inside a validation loop: (A) // add 1 to Count, or (B) // count the number of failed attempts?
Comment A only repeats what the code already says.
Comment B explains the purpose: what the count is for.
Answer: B: comments should explain why, not repeat the code
Examiner trap
Comments are ignored by the translator, so they do not make the program run faster or slower, and they do not fix errors. They help people.
Stage 1 · Learn
Check what the sim just showed you
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Quick check+10 XP
Which identifier is the most meaningful for the number of lives a player has left?
Quick check+10 XP
How does a comment begin in 0478 pseudocode?
Quick check+10 XP
Why use a constant for a VAT rate rather than typing 0.2 throughout the program?
Quick check+10 XP
Which is a valid 0478 pseudocode identifier?
Section 03
Constants and subroutines.
Each program in the lab has one mistake. As you hunt for it, notice how meaningful names and a clear structure make the faulty line easier to find.
Constants: a value such as a tax rate is written once, with a meaningful name; if it changes, only one line is edited, and it cannot be changed by mistake while the program runs.
Procedures and functions: code that is needed several times is written once and called by name; a fix is made in one place.
Structure: each subroutine does one clear job, so it can be tested on its own and different programmers can work on different parts.
Layout: consistent indentation inside IF statements and loops shows which statements belong together.
Worked example Improve this code
A program contains the line P ← C * 1.2 in five places, where 1.2 adds 20% tax. Suggest three improvements to make it maintainable.
Rename the variables, e.g. PriceWithTax and CostPrice.
Declare CONSTANT TaxMultiplier ← 1.2 and use it instead of 1.2, so a tax change is one edit.
Put the calculation in a function, e.g. AddTax(CostPrice), called in all five places, with a comment explaining it.
Answer: Meaningful identifiers, a constant and a function (with a comment)
Stage 2 · Exam
Exam-style questions
Unlocks once the four checks above are done. Worth more XP, written to IGCSE Paper 1 standard.
Finish the four checks above to unlock the exam questions
Exam style+20 XP
Which TWO techniques make a program more maintainable?
Exam style+20 XP
What is the purpose of comments in a program?
Exam style+20 XP
Which identifier is NOT allowed in 0478 pseudocode?
Exam style+20 XP
How does using procedures and functions make a program easier to maintain?
Skill unlocked
Maintainable programs, mastered.
This skill is now recorded on your profile. Keep the chain going.