A recipe that says "cook until done"
A recipe that says "cook until done" is no help if you have never cooked.
You send your design to a builder you have never met. You are away. They cannot ask you anything.
If a step says "check the booking", the builder must guess how. If a step says "if the hour is before 9, output Closed", the builder knows.
A good design can be built by a stranger.
Key words
| Word | What it means | Example |
|---|---|---|
| Sequence | Steps done one after another, in order. | ask, check, save |
| Selection | A choice of path, made by a yes or no answer. | if the hour is 21, refuse |
| Iteration | Doing steps again and again. | for each hour from 9 to 20 |
| Loop | Code or a flowchart path that repeats steps. | while hour <= 20 (<= means 20 or less) |
| Flowchart | A diagram of steps with arrows. | start, check, book |
| Reusable component | A part you write once and use in many places. | price_for() |
| Sub-system | One big part of the whole solution. | prices, storage, screen |
| Naming convention | A rule for how names are written, used the same way everywhere. | small letters with _ between words, like book_court |
| Third party | A person outside your team who uses your work. | another developer |
| Audience | The people who read your design. | the manager, the builder |
The cells students fill in are left blank in this preview.
The three building blocks of every algorithm
| Construct | Flowchart shape | Hillside example | Python |
|---|---|---|---|
| Sequence | Boxes joined by arrows | Input the hour, then input the court, then save | Lines one after another |
| Selection | A diamond with yes and no | Is the hour from 9 to 20? | if ... else |
| Iteration | An arrow that goes back up | Do this for every hour from 9 to 20 | for or while |
The cells students fill in are left blank in this preview.
Which building block is it?
Have a go
Which building block is it?
5 questionsA flowchart with a loop: show the day
flowchart TD
start([Start]) --> a[Set hour to 9]
a --> d{Is the hour 20 or less?}
d -->|yes| o[/Output: the hour and who booked it/]
o --> n[Add 1 to the hour]
n --> d
d -->|no| e([End])
Try it: the same loop in Python
names = {10: "Sam", 12: "Aisha"}
hour = 9
while hour <= 20:
if hour in names:
print(hour, names[hour])
else:
print(hour, "free")
hour = hour + 1
# The arrow going back up is the while line.
# <= means "is less than or equal to".
# Change 20 to 12 and run it again.
Make a free account to save your work and track your progress.
Check: building blocks
Have a go
Check: building blocks
4 questionsA reusable part is written once
The price rule is needed in three places: when a booking is made, when it is cancelled, and in the manager's report.
Do not write it three times. Write one reusable component, price_for, and call it from all three. When the price changes, you change one place.
In a design, draw each reusable part once and show every other part using it.
Sub-systems of the booking tool
flowchart TD
tool([Booking tool])
tool --> screen[Screen: forms and messages]
tool --> rules[Rules: hours and courts]
tool --> prices[Prices: price_for]
tool --> store[Storage: the file of bookings]
screen --> rules
rules --> store
screen --> prices
Check: one naming style
Have a go
Check: one naming style
3 questionsStage 3: turn the loop into code
Turn the loop flowchart into code. booked_hours lists the booked hours in order. day_lines gives one line for each hour from 9 to 20: "10: Sam" or "9: free". free_hours gives the free hours. Use booked_hours inside free_hours, so the idea is written only once. Press Run Tests to check your work.
def booked_hours(bookings):
# bookings is a list like [(10, "Sam"), (12, "Aisha")]: (hour, name).
# booking[0] is the hour and booking[1] is the name.
# Give back the booked hours as a list, from the earliest to the latest.
return None
def day_lines(bookings):
# Give back 12 lines of text, one for each hour from 9 to 20.
# A booked hour looks like "10: Sam". A free hour looks like "9: free".
return None
def free_hours(bookings):
# Give back the free hours from 9 to 20 as a list, earliest first.
# Use booked_hours so the idea is written only once.
return None
Make a free account to save your work, or press Start lab to work through the whole lesson.
Weak steps and strong steps
| Weak step | Why it is weak | Strong step |
|---|---|---|
| Check the booking | It does not say how | If the hour is below 9 or above 20, output Closed and stop |
| Work out the price | Which price? | If the person is a member, the rate is 4. If not, the rate is 6. Price is rate times hours |
| Save it | Where? In what form? | Add one line to the bookings file: name, court, hour |
The cells students fill in are left blank in this preview.
Write for the person who reads it
Two people read your design.
The client is the person who asked for the tool. The client wants the main idea, a picture of the screen and what it will cost. Use plain words.
The builder wants every step, every field and every rule. Use the right technical words.
Use both words and diagrams. A diagram shows the shape. Words give the detail.
Stage 3: write a design note
This is stage 3 of the Hillside practice project. Design one new feature: cancel a booking. Part A: write three plain sentences for Mrs Okafor, the client. Say what the feature does and what she will see. Part B: write numbered steps for a builder. Every step does one thing. Use at least one selection and one iteration. Part C: list the names you will use for the function and the data, in one naming style. Part D: say which part you reuse from the rest of the tool.
A teacher marks this in a college. Nothing you write here is kept: it goes when you leave the page.
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go