Readability (SQA National 5 Computing Science): Revision Note

Exam code: X816 75

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

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

totalScore is clearer than x

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

RECEIVE b FROM (REAL) KEYBOARD
RECEIVE h FROM (REAL) KEYBOARD
SET a ← 0.5*b*h
SEND "area " & a TO DISPLAY
b=float(input("b:"))
h=float(input("h:"))
a=0.5*b*h
print("area",a)
  • 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

# Program to calculate the area of a triangle

RECEIVE base FROM (REAL) KEYBOARD
RECEIVE height FROM (REAL) KEYBOARD

SET area ← 0.5 * base * height

SEND "The area of the triangle is " & area & " square units" TO DISPLAY
# Program to calculate the area of a triangle

# Input base and height
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))

# Calculate the area
area = 0.5 * base * height

# Display the result
print("The area of the triangle is", area, "square units")
  • 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!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.