All subjects · Computer Science · WCP02 Practical Programming and Problem-solving
Designing programs: decomposition, scope and side effects
Edexcel IAL Computer Science · WCP02 Practical Programming and Problem-solving
Good design produces correct results and code that is easy to change. The specification names the methods and practices examiners look for.
Methods to produce correct outcomes (spec 9.1.1)
- Decompose the problem into component parts (input, validation, processing, output), each small enough to code and test on its own.
- Use clear and appropriate logic: conditions in the right order, loops that start and stop correctly.
- Choose variables, constants, data types and structures that suit the data: a 2D list for a table, a dictionary for look-ups, a constant for a fixed limit.
- Choose constructs that suit the problem: for when the number of passes is known, while when it is not.
Scope isolation and side effects (spec 9.1.2)
A local variable exists only inside its subprogram; a global one is visible everywhere. A side effect is any change a subprogram makes outside itself: changing a global, printing, writing a file, or changing a list passed in. Isolate scope by passing data in as parameters and returning results.
count = 0
def add_global():
global count
count = count + 1
def add_pure(n):
return n + 1
add_global()
total = add_pure(5)
print(count, total)
def append_item(items):
items.append(99)
data = [1, 2]
append_item(data)
print(data)Output:
1 6
[1, 2, 99]A list passed to a subprogram is the same list, so changes inside it are seen outside: a side effect. Copy the list first if the original must stay unchanged.
Other good design practice
- Modularity and separation of concerns: each subprogram does one job, for example one reads the file, one validates, one calculates, one displays.
- Fitness of purpose for input and output: prompts that say what to type, output that is clearly labelled and formatted as asked.
- Efficiency: fewer passes through the data (execution time) and no unnecessary copies of large structures (memory). The sample paper gave a mark for processing the data in a single pass.
Efficiency in practice
Finding the largest and smallest values in one loop does half the work of two separate loops:
readings = [14, 9, 22, 17, 5]
low = readings[0]
high = readings[0]
passes = 0
for r in readings:
passes = passes + 1
if r < low:
low = r
if r > high:
high = r
print(low, high, passes)Output:
5 22 5Worked example
Decompose this task: 'Read pupils' marks from a file, reject marks outside 0 to 100, and display each valid pupil's grade in a table.'
- load_marks(filename): reads the file into a 2D list and returns it
- is_valid(mark): returns True if 0 <= mark <= 100
- grade(mark): returns the grade letter for a mark
- show_table(records): displays the formatted table
- The main program calls these in order and passes data between them as arguments and return values.
Answer: Four subprograms, each with one job, joined by parameters and return values
Check yourself
- What is displayed when this code runs?
```python
x = 10
def change():
x = 50
return x
y = change()
print(x, y)
```
Show answer
10 50. Inside change(), x = 50 creates a new local variable; the global x is still 10: 10 50.
- What is displayed when this code runs?
```python
x = 10
def change():
global x
x = 50
change()
print(x)
```
Show answer
50. global x makes the function change the global variable: 50.
- What is displayed when this code runs?
```python
def double_all(values):
for i in range(len(values)):
values[i] = values[i] * 2
nums = [1, 2, 3]
double_all(nums)
print(nums)
```
- [2, 4, 6]
- [1, 2, 3]
- None
- [1, 2, 3, 2, 4, 6]
Show answer
[2, 4, 6]. The function receives the same list, so changing values changes nums: [2, 4, 6]. This is a side effect.
- What is displayed when this code runs?
```python
def area(w, h):
result = w * h
return result
a = area(3, 4)
print(a)
```
Show answer
12. result is local to area(), but its value is returned and stored in a: 12.
- Which exception is raised when this code runs?
```python
def setup():
limit = 5
setup()
print(limit)
```
- UnboundLocalError
- NameError
- TypeError
- ValueError
Show answer
NameError. limit only exists inside setup(), so using it outside raises NameError.
- Which design shows the clearest separation of concerns?
- One subprogram reads, calculates and displays everything
- Every line is written in the main program with no subprograms
- Each subprogram changes the same global variables
- One subprogram reads the data, another calculates the totals, another displays them
Show answer
One subprogram reads the data, another calculates the totals, another displays them. Each part has one job, so it can be understood, tested and changed on its own.
- A program finds the total, the maximum and the minimum of 10 000 readings. Which approach is most efficient?
- Three separate loops, one for each value
- One loop that updates all three as it goes
- Sort the list three times, then read the ends
- Copy the list into three new lists first
Show answer
One loop that updates all three as it goes. A single pass visits each reading once, instead of three times, and needs no extra copies.
Sources
- Pearson Edexcel International Advanced Subsidiary/Advanced Level in Computer Science specification (XCP01/YCP01), first teaching 2026
- Pearson IAL Computer Science Unit 2 Programming Language Subset (PLS), Python 3
- Pearson IAL Computer Science IAS sample assessment materials (Unit 2 paper and mark scheme)
Last updated 8 November 2026. Spotted a mistake? Tell us.