Readability (SQA National 5 Computing Science): Revision Note
Exam code: X816 75
Readability
What is readability?
Readability means how easy a program is to read, understand, and maintain
A readable program allows another person (or the original programmer) to understand what it does quickly and make changes without confusion
You must be able to describe, identify, and exemplify the four main techniques that make a program readable
Techniques that improve readability
Technique | Description | Example / Why it helps |
|---|---|---|
Internal commentary | Short comments that explain what parts of the program do | Helps others understand the purpose of each section |
Meaningful identifiers | Variable names clearly describe the data they store |
|
Indentation | Indenting code inside loops or conditions | Makes the structure of the program easy to follow |
White space | Adding blank lines to separate sections of code | Improves layout and makes sections stand out |
Before and After example
Before (hard to read)
SQA Pseudocode | Python |
|---|---|
| |
This code works, but it’s poorly laid out:
Variable names are short and meaningless
There are no comments
No white space separates the stages of the program
After (readable and well-maintained)
SQA Pseudocode | Python |
|---|---|
| |
This version is easy to read because it:
Uses meaningful variable names (
base,height,area)Includes internal comments to explain each section
Uses white space between input, process, and output
Is consistently indented
Examiner Tips and Tricks
When asked how to improve readability or maintainability:
Mention two or more techniques (commenting, indentation, white space, identifiers)
Avoid vague answers like “make the code better” — describe how and why
Worked Example
A programmer is developing a small program snippet to calculate the total cost of a service, which involves adding a fixed rate to a charge calculated as 10% of the duration.
The programmer writes the following pseudocode:
Line 1: RECEIVE dur FROM KEYBOARD
Line 2: RECEIVE rate FROM KEYBOARD
Line 3: SET tot TO dur * 0.10 + rate
Line 4: SEND "Your total is " & tot TO DISPLAY
(i) Identify and explain one reason why this code snippet is considered to have poor readability, referencing a specific line number.
[2]
(ii) Rewrite the entire code snippet, ensuring you improve readability by using meaningful identifiers.
[2]
Answers
(i)
Poor use of meaningful identifiers [1 mark]
Does not clearly indicate what data they represent [1 mark]
Making it difficult for someone reading the code to immediately understand the program's purpose or the meaning of the calculation
(ii)
Line 1: RECEIVE duration_minutes FROM KEYBOARD
Line 2: RECEIVE fixed_rate FROM KEYBOARD
Line 3: SET total_cost TO duration_minutes * 0.10 + fixed_rate
Line 4: SEND "Your total is " & total_cost TO DISPLAY[2 marks]
Unlock more, it's free!
Did this page help you?