SDD  Β·  Software Design & Development

Evaluation and Code Quality

Lesson 16 of 19 Approx 55 min Requires: SDD1 Development Methodologies, SDD15 Testing
Learning intentions
  • Understand why evaluation is the final stage of the iterative development process
  • Describe, identify, and exemplify all four SQA evaluation criteria for a software solution
  • Apply evaluation criteria to code examples and explain specific improvements
Success criteria
  • I can define fitness for purpose and explain how to check a program meets its requirements
  • I can define robustness and identify whether a program handles invalid input correctly
  • I can define efficient use of coding constructs and give a specific code example
  • I can define readability and identify all four sub-criteria: commentary, meaningful identifiers, indentation, and white space
  • I can evaluate a given program against all four criteria and justify my judgement with evidence from the code
Warm up β€” what do you already know?

Answer before the lesson begins.

1. Evaluation is one of the six stages of the iterative development process. When does it take place?

2. A program asks the user for their age. The user types "twenty". What does a robust program do?

3. Which of the following variable names is the most readable?

Key vocabulary

evaluation
Judging how well a completed software solution meets the requirements set out during analysis. The SQA specifies four criteria: fitness for purpose, robustness, efficient use of coding constructs, and readability.
fitness for purpose
The program does everything specified in the functional requirements. Every input, process, and output listed during analysis must work correctly.
robustness
The program handles invalid, unexpected, or out-of-range input without crashing. Typically achieved through input validation.
efficient use of coding constructs
The program uses the most appropriate structure for each task. For example: ELSE IF instead of repeated IFs; a loop instead of repeated lines; a predefined function instead of writing the same code multiple times.
readability
Another programmer can understand the code without needing to ask questions. Achieved through internal comments, meaningful identifiers, consistent indentation, and white space.
meaningful identifier
A variable, array, or function name that describes its purpose. totalScore is meaningful; x is not.

The four evaluation criteria

The SQA specification requires you to evaluate a software solution against exactly four criteria. For each one, you must be able to describe what it means, identify whether a program has it, and exemplify it with specific evidence from code.

1. Fitness for purpose Does the program do what it was designed to do? βœ” All inputs work correctly βœ” All processes produce correct results βœ” All outputs match the specification Compare output to the functional requirements written at the analysis stage 2. Robustness Does it handle invalid input without crashing? βœ” Validates all user inputs βœ” Shows a clear error message for bad input βœ” Loops back and asks the user to try again Uses input validation standard algorithm (WHILE loop, read-before-loop pattern) 3. Efficient use of coding constructs Is the code as concise and clear as it could be? βœ” Loops avoid repetitive code βœ” Arrays used instead of many single variables βœ” Subprograms used for repeated logic Could a loop replace repeated copy-pasted code? 4. Readability Can another programmer understand the code? βœ” Commentary β€” explains purpose of key lines βœ” Meaningful identifiers β€” totalScore not x βœ” Indentation β€” code inside loops/ifs indented βœ” White space β€” blank lines between sections 4 sub-criteria β€” all must appear in your answer

1. Fitness for purpose

Does the program do what it was designed to do? To evaluate this, go back to the functional requirements from the analysis stage and check each one:

  • Does every input listed work correctly?
  • Does every process produce the right result?
  • Does every output appear as specified?

A program is fit for purpose if it meets all requirements. If it meets most but not all, it is partially fit for purpose β€” and you should identify which requirement is not met.

2. Robustness

Does the program handle invalid input without crashing? A robust program:

  • Validates input before processing it
  • Displays a meaningful error message when input is invalid
  • Gives the user the chance to try again
  • Does not crash or produce garbage output when unexpected data is entered

At N5 level, robustness is primarily achieved through the input validation standard algorithm (SDD14b). A program that uses int(input(...)) without any validation is not robust β€” it will crash if the user types a letter.

3. Efficient use of coding constructs

Does the program use the right tool for each job? The SQA is specifically looking for situations where a less efficient approach was replaced with a more efficient one. The most common examples at N5 are:

SituationInefficientEfficient
Multiple conditionsThree separate IF statements (all three are always evaluated)IF / ELSE IF / ELSE (stops at the first match)
Repeated codeSame block of code copied 10 timesA loop that runs 10 times
Common calculationWriting the same formula in multiple placesA predefined function called wherever needed
Array traversalAccessing array[0], array[1], array[2]… individuallyA loop with an index variable

Key point for the exam: ELSE IF is more efficient than multiple IF statements because when one condition is true, the rest are skipped. With separate IFs, the computer evaluates every single one.

4. Readability

The SQA specifies four sub-criteria for readability. All four can be examined:

Sub-criterionWhat it meansExample
Internal commentaryComments in the code that explain what sections do. In Python, lines starting with #.# Calculate the average score
Meaningful identifiersVariable, array, and function names that describe their purpose.totalScore not x
IndentationCode inside loops, IF statements, and functions is consistently indented (4 spaces in Python). Makes the structure visible.Lines inside for indented by 4 spaces
White spaceBlank lines between sections of code. Makes the code easier to scan.Blank line between variable declarations and the main loop

Before and after β€” applying the criteria

Readability β€” poor vs improved
βœ• Poor readability
x=0
for i in range(5):
  n=int(input("?"))
  x=x+n
print(x/5)
βœ“ Good readability
# Collect 5 scores and calculate the average
total = 0

for question in range(1, 6):
    score = int(input("Enter score for Q" + str(question) + ": "))
    total = total + score

average = total / 5
print("Average score:", average)

Improvements: comment added; meaningful identifiers (total, score, average, question); consistent 4-space indentation; blank line before the loop and before the output.

Efficient use β€” separate IFs vs ELSE IF
βœ• Inefficient β€” 3 IFs always evaluated
if score >= 70:
    grade = "A"
if score >= 50 and score < 70:
    grade = "B"
if score < 50:
    grade = "Fail"
βœ“ Efficient β€” stops at first match
if score >= 70:
    grade = "A"
elif score >= 50:
    grade = "B"
else:
    grade = "Fail"

If score is 80, the first condition is True. With separate IFs, conditions 2 and 3 are still evaluated. With ELSE IF (elif), Python jumps straight to END IF β€” more efficient.

Robustness β€” no validation vs validated
βœ• Not robust β€” crashes on invalid input
age = int(input("Enter your age: "))
# If user types "hello", this crashes
# with ValueError: invalid literal
βœ“ Robust β€” validates range
age = int(input("Enter your age (0-120): "))
while age < 0 or age > 120:
    print("Invalid. Enter age 0-120.")
    age = int(input("Try again: "))

Note: the improved version validates the range β€” it still assumes the user enters a number. Full robustness (handling non-numeric input) requires exception handling, which is beyond N5 scope.

How to write an exam evaluation

In the exam, you may be shown a program and asked to "evaluate this solution" or asked about a specific criterion. Always:

  1. Name the criterion β€” use the SQA term exactly.
  2. State your judgement β€” is it good, poor, or could be improved?
  3. Give specific evidence from the code β€” quote a line number, variable name, or specific construct.

Example answer β€” fitness for purpose

"The program is fit for purpose. The functional requirements stated that the program should accept a score, calculate the grade, and display it. All three requirements are met: line 3 receives the score, lines 5–10 calculate the grade using ELSE IF, and line 12 displays the result."

Example answer β€” readability

"The readability could be improved. The variable name x on line 1 is not meaningful β€” it should be renamed totalScore to make its purpose clear. There are also no internal comments to explain what each section of the program does."

Example answer β€” efficient use

"The program makes efficient use of coding constructs. Lines 6–10 use an ELSE IF chain rather than three separate IF statements. This is more efficient because once the first matching condition is found, the remaining conditions are not evaluated."

Now you try

Evaluate the program below against all four criteria. Give specific evidence from the code for each one.

t = 0
for i in range(10):
    n = int(input("number: "))
    t = t + n
print(t)

Fitness for purpose: Partially fit for purpose. The program collects 10 numbers and outputs their total. If the requirement was to display the total and average, it would not be fit for purpose as it only shows the total.

Robustness: Not robust. There is no input validation β€” if the user enters a non-numeric value, the program will crash with a ValueError. Adding a WHILE loop to check the input is within range would improve robustness.

Efficient use of coding constructs: Efficient. A FOR loop is used to collect 10 numbers rather than repeating the input line 10 times. The accumulator pattern (t = t + n) is the correct construct for a running total.

Readability: Poor. Variable names t, i, and n are not meaningful β€” they should be total, counter, and number. There are no internal comments. No white space separates the loop from the output statement.

Common mistakes
βœ•
Giving a vague evaluation without evidence. Saying "the program is readable" is worth 0 marks. You must say why β€” e.g. "the variable totalScore is a meaningful identifier" or "there are comments on lines 2 and 7 explaining each section."
βœ•
Confusing robustness with fitness for purpose. Fitness for purpose is about meeting requirements. Robustness is specifically about handling invalid input. A program can be fit for purpose but not robust.
βœ•
Missing sub-criteria for readability. The SQA recognises four: internal commentary, meaningful identifiers, indentation, and white space. An answer that only mentions comments misses three marks.
βœ•
Saying ELSE IF is "shorter" rather than "more efficient". The SQA mark scheme looks for the word efficient and the explanation that remaining conditions are not evaluated once a match is found.
Exam tip

Evaluation questions are among the highest-value questions in the SDD section. They are often worth 3–4 marks and require you to name, judge, and justify for each criterion. If the question says "evaluate the solution", cover all four criteria. If it says "evaluate the readability", cover all four readability sub-criteria.

The phrase the SQA uses for efficient use is: "efficient use of coding constructs". Use these exact words in your answer, not "good code" or "no repetition."

Task set
Q1–Q4 knowledge recall  Β·  Q5–Q8 written evaluation  Β·  Q9–Q10 extended tasks

1. Which evaluation criterion specifically concerns the program handling invalid input without crashing? TYPE 1

2. A program uses three separate IF statements to check if a score is an A, B, or C grade. A student says this could be improved for efficiency. What should they replace them with? TYPE 1

3. Which of the following is NOT one of the four SQA sub-criteria for readability? TYPE 1

4. A program was required to: (a) accept a name and age, (b) check the age is valid, and (c) output a welcome message. The program accepts the name and age and outputs the message, but does no validation. How would you evaluate its fitness for purpose? TYPE 1

5. Evaluate the readability of the code below. Refer to all four SQA sub-criteria in your answer. TYPE 2

a=0
b=0
for i in range(5):
    n=int(input("?"))
    a=a+n
b=a/5
print(b)

Internal commentary: Poor. There are no comments in the program. A comment before the loop explaining that it collects 5 numbers, and one before the final line explaining the average calculation, would improve readability.

Meaningful identifiers: Poor. The variable names a, b, i, and n give no indication of what each variable holds. They should be renamed: a β†’ total, b β†’ average, i β†’ counter, n β†’ score.

Indentation: Partially acceptable. The two lines inside the FOR loop are indented, but inconsistently β€” they appear to use 4 spaces in one place and less in another. Consistent 4-space indentation should be used throughout.

White space: Poor. There are no blank lines between the variable declarations, the loop, and the output. Adding blank lines between these sections would make the structure of the program much clearer.

6. The following program was written to meet these requirements: (1) ask the user for a temperature in Celsius, (2) convert it to Fahrenheit using the formula F = C Γ— 1.8 + 32, (3) display the result. Evaluate it for fitness for purpose and robustness. TYPE 2

celsius = float(input("Enter temperature in Celsius: "))
fahrenheit = celsius * 1.8 + 32
print("Temperature in Fahrenheit:", fahrenheit)

Fitness for purpose: Fully fit for purpose. All three requirements are met: line 1 accepts a Celsius temperature from the user; line 2 applies the correct conversion formula (C Γ— 1.8 + 32); and line 3 displays the result in Fahrenheit. The program would produce the correct output for any valid numeric input.

Robustness: Not robust. There is no input validation. If the user enters a non-numeric value (e.g. "hot"), the program will crash with a ValueError on line 1. A WHILE loop should be added to validate that the input is within a realistic range, such as βˆ’273 to 1000 degrees Celsius. The program also does not handle the case where the user enters no value.

7. Evaluate the efficient use of coding constructs in the code below. Identify one inefficiency, explain why it is inefficient, and rewrite that section using a more efficient construct. TYPE 2

score = int(input("Enter score: "))
if score >= 70:
    print("Grade A")
if score >= 50 and score < 70:
    print("Grade B")
if score >= 30 and score < 50:
    print("Grade C")
if score < 30:
    print("Fail")

Inefficiency identified: Four separate IF statements are used. This means every condition is evaluated every time the program runs, even after a matching condition has been found. For example, if score is 85, the first condition is True and "Grade A" is printed β€” but conditions 2, 3, and 4 are still checked unnecessarily.

Why inefficient: With four separate IFs, the computer always performs four comparisons. With ELSE IF, it stops as soon as a match is found β€” potentially only one comparison is needed.

Rewritten:

score = int(input("Enter score: "))
if score >= 70:
    print("Grade A")
elif score >= 50:
    print("Grade B")
elif score >= 30:
    print("Grade C")
else:
    print("Fail")

8. Write a full evaluation of the program below against all four SQA criteria. The program was required to: collect 5 pupil names from the user, store them in an array, and display them all. TYPE 2

n=[]
for i in range(5):
    x=input("?")
    n.append(x)
for i in range(5):
    print(n[i])

Fitness for purpose: Fully fit for purpose. The program collects 5 names (FOR loop, lines 2–4), stores them in an array (line 4 appends each to n), and displays all five (FOR loop, lines 5–6). All three requirements are met.

Robustness: Robustness is not applicable for string input β€” any text the user types is valid. However, the input prompt ("?") gives no information about what to enter, which could lead to user error. A more descriptive prompt would improve the user experience.

Efficient use of coding constructs: Efficient. Two FOR loops are used rather than writing the input and print lines five times each. This is an appropriate and efficient use of loops for a fixed number of iterations.

Readability: Poor. Variable names n, i, and x are not meaningful β€” they should be names, counter, and pupilName. There are no internal comments. There is no white space between the two loops. Indentation appears consistent (acceptable).

9. In PyCharm, write a program that deliberately demonstrates all four evaluation criteria being met. The program should: ask the user for 3 temperatures (validate: between -50 and 60), calculate and display the average temperature, and state whether the average is above or below freezing (0Β°C). Your code must include: (a) at least two comments, (b) meaningful variable names throughout, (c) consistent indentation, (d) blank lines between sections, (e) input validation for robustness, and (f) ELSE IF / else for the above/below freezing check. TYPE 3

# Program to collect 3 temperatures and calculate the average
total = 0

for reading in range(1, 4):
    temperature = float(input("Enter temperature " + str(reading) + " (-50 to 60Β°C): "))
    while temperature < -50 or temperature > 60:
        print("Invalid. Temperature must be between -50 and 60 degrees Celsius.")
        temperature = float(input("Enter temperature " + str(reading) + " (-50 to 60Β°C): "))
    total = total + temperature

# Calculate average and determine whether it is above or below freezing
average = total / 3
print("Average temperature:", round(average, 1), "Β°C")

if average > 0:
    print("The average temperature is above freezing.")
elif average == 0:
    print("The average temperature is exactly at freezing point.")
else:
    print("The average temperature is below freezing.")

This solution demonstrates: internal comments (lines 1 and 11); meaningful identifiers (total, reading, temperature, average); consistent 4-space indentation; blank lines between sections; robustness via input validation; and efficient use of elif.

10. The program below has poor readability and makes inefficient use of coding constructs. In PyCharm, rewrite the entire program to fix both issues. Add comments, rename all variables to meaningful names, add white space, and replace the repeated IFs with ELSE IF. Test both versions to confirm they produce the same output. TYPE 3

p=int(input("p?"))
if p>=90:
    print("gold")
if p>=70 and p<90:
    print("silver")
if p>=50 and p<70:
    print("bronze")
if p<50:
    print("no medal")

# Medal award program β€” determines medal based on percentage score
percentage = int(input("Enter your percentage score (0-100): "))

# Award medal based on score bracket
if percentage >= 90:
    print("Gold medal")
elif percentage >= 70:
    print("Silver medal")
elif percentage >= 50:
    print("Bronze medal")
else:
    print("No medal awarded")

Improvements made:

Readability: p renamed to percentage (meaningful identifier); two comments added; blank line before the IF block; input prompt now descriptive.

Efficiency: four separate IFs replaced with IF / ELIF / ELSE β€” the computer now stops evaluating conditions as soon as a match is found.

Teacher notes β€” Shift+T to hide

Suggested timing: 55 minutes. Warm up 7 min; vocab + notes 15 min; before/after examples 10 min; now you try 5 min; task set Q1–Q8 13 min; PyCharm Q9–Q10 15 min (or set as homework).

Common pupil confusion: evaluation vs testing. Testing checks whether the program produces correct outputs for given inputs. Evaluation makes a broader judgement about the quality of the solution. They are related but distinct β€” a program can pass all tests and still have poor readability or inefficient code.

Efficient use β€” the key teaching point. Write both versions of the grade checker on the board side by side. Ask pupils: "If score is 85, how many IF comparisons does version A do? How many does version B (ELSE IF) do?" Version A: 4. Version B: 1. This makes the efficiency difference concrete.

Readability task: Give pupils a printout of a real piece of pupil code (anonymised) with poor readability. Ask them to annotate it β€” identify which sub-criteria are missing and rewrite it with improvements. This is more engaging than working from a textbook example.

SQA mark scheme language. Pupils must use "efficient use of coding constructs" β€” not "efficient code" or "no repeated lines". Similarly for robustness β€” must reference "invalid input" not just "errors".