Phase 1: Prepare
Step 1 Warm-up recall
From Module 7: what is the first step of debugging?
Private: nothing you type here is sent or stored.
Step 2 Learning goal
By the end of this lesson you can:
- state the user, need, inputs and outputs (Foundation);
- work an example by hand (Core);
- split the task into functions (Core).
Phase 2: Teach
Step 3 A familiar example
An architect draws plans before any bricks are laid, and the client agrees to them. A program is planned the same way, on paper, before any code is typed.
Step 4 Clear explanation
Choose a small, useful program: a stock report, a marks summary or a weekly spending total. Plan it in five answers.
- User and need: who will use it, and what decision will it help with?
- Inputs: which file or values, in what form, with which known problems?
- Outputs: what exactly will it show or write, and where?
- A worked example: a tiny input and the output you expect, worked out by hand. This becomes your first test.
- Functions: one job each, with a name and a stated unit.
# Plan: stock report
# Need: shop owner wants items below reorder level
# Input: stock.csv with columns item,qty,reorder
# Output: list of items to reorder, and a count
#
# Functions:
# load_rows(path) -> rows, bad_count
# needs_reorder(row) -> True or False
# make_report(rows) -> list of item names
#
# Example: pen,3,5 -> reorder; ink,9,5 -> fineThe plan is short, but it already settles what the program does and does not do. If a user asks for something outside it, you can say so clearly, and add it later as a new function.
Step 5 Worked example (4 marks)
A stock file has the rows pen,3,5, ink,9,5 and pad,5,5. Using the rule "reorder when qty is at or below the reorder level", what should the report list?
- pen: 3 is below 5, so reorder. (1 mark)
- ink: 9 is above 5, so fine. (1 mark)
- pad: 5 equals 5, which is at the level, so reorder. (1 mark)
- Answer: pen and pad; pad is the boundary case. (1 mark)
Go deeper: the professor's notes
Who and why.
Files.
Report.
Plan
| Question | Answer |
|---|---|
| who uses it | the shop owner |
| what comes out | items to reorder |
At work: A stock report
An owner wants to know what to reorder.
- Write the five answers.
- Work one example by hand.
What a careful practitioner decides. A paper plan costs far less than a code change.
Phase 3: Practise
Step 6 Learner practice (instant-marked)
1. The first thing to settle in a plan is:
Start from the user.
2. A worked example done by hand becomes:
It is the known answer.
3. Each function in the plan should have:
One job.
4. Why plan on paper first?
Changing a plan is cheap.
Phase 4: Close
Step 7 Recap
- Name the user, need, inputs and outputs.
- Work a small example by hand as your first test.
- Split into functions with one job each.
Step 8 Exit ticket (ungraded)
Write the user, need, input and output for a program you would find useful.
Private: nothing you type here is sent or stored.
Step 9 Go further (Extension)
Draft the function list for your capstone program and one hand-worked example.
In industry: Heathrow Terminal 5: test filters left in place
During testing of the baggage system at Heathrow's Terminal 5, technicians installed software filters to stop test messages reaching live systems. They were accidentally left in place after the terminal opened on 27 March 2008, so some messages about transferring bags were not received. In the first five days more than 23,000 bags were misplaced and 500 flights were cancelled.
Link to this lesson. Remove test settings before release and check what the live system receives.
Source: Computer Weekly, 14 May 2008; House of Commons Transport Committee, The Opening of Heathrow Terminal 5
Common mistakes
| Mistake | Why it fails |
|---|---|
| Coding before planning | Plan inputs, outputs and an example first. |
| A plan too big to finish | Choose a small, useful program. |
| No worked example | You will have nothing to test against. |
Limits. This lesson plans a program of a few functions; larger systems need more design and a team.