Two ways to make a video
Anna wants to post a video. First she plans the whole video: the start, the middle and the end. Then she films each part.
Ben films short clips all week: a trick shot, a funny moment, a goal. Then he joins the best clips and sees what video they make.
Both ways work. Which way do you work? Programmers use both.
Key words
| Word | What it means | Example |
|---|---|---|
| Top-down | Start with the whole problem. Break it into smaller and smaller parts. | Anna plans the whole video, then films each part |
| Bottom-up | Start with small parts you can build. Join them to make the whole. | Ben films clips, then joins them into a video |
| Modularisation | Splitting a program into separate modules. Each module does one job. | a login module, a payment module |
| Module | A separate part of a program with one job. | a file of functions |
| Function | A named piece of code that does one job. | def area |
| Reuse | Use a part again in a new place. | the same login in two apps |
The cells students fill in are left blank in this preview.
Match the word to what it means
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Top-down: from the whole to the parts
Top-down starts with the goal
Top-down starts at the top. You first decide what the whole thing must do. Then you break each part into smaller parts, again and again, until each part is easy to build.
It is a good choice when you know the goal and the problem is big.
Bottom-up starts with parts you trust
Bottom-up starts at the bottom. You build small parts you already know how to make. You test each one. Then you join them to make something bigger.
It is a good choice when you have good parts already, or when you are not sure what the whole will be.
Top-down or bottom-up?
Have a go
Top-down or bottom-up?
3 questionsEach module does one job
Modularisation means splitting a program into modules. Each module has one job and clear inputs and outputs.
Other parts of the program use a module without knowing how it works inside. You can test a module alone. You can reuse it in another program.
Try it: use a module
import math
print(math.sqrt(16))
print(math.pi)
# math is a module that other people wrote.
# You use it without seeing how it works inside.
# Change 16 to 25 and run it again.
Make a free account to save your work and track your progress.
Watch: top-down, bottom-up and modules
Press Play on the short film below. It builds the sports day app twice: top-down from the whole app, then bottom-up from its small parts. Then it shows what a module is and why it helps. Watch which way the arrow points in each.
Film: top-down, bottom-up and modules
Top-down, bottom-up and modules
Every scene, as text
- Top-down: start with the whole problem and break it into smaller and smaller parts. The School sports day app breaks into Register runners, Run the races and Show results, and those break again until each part is easy to build. It is a good choice when you know the goal and the problem is big.
- Bottom-up: start with small parts you can build, test each one, then join them to make the whole. Register runners, Record the time, Work out the place and Show the table are built and tested first, then joined into Run the races and Show results, and on up to the whole app. It is a good choice when you have good parts already, or when you are not sure what the whole will be. Real projects often mix both.
- Modularisation means splitting a program into modules. A module is a separate part of a program with one job. Each main part of the app can be its own module, holding its smaller parts, so a team can work at the same time, one person on each module. Modularisation is how the parts are packaged, not a third way to plan.
- Reuse means using a part again in a new place: the same Login module works in a Shop app and in a Game app. A module can also be tested alone, so a bug is easier to find.
- math is a module other people wrote. import math brings it in, print(math.sqrt(16)) prints 4.0 and print(math.pi) prints 3.141592653589793. You use a module without seeing how it works inside.
- Myth (false): a module and a function are the same. A function is a named piece of code that does one job, like area. A module is a bigger unit, often a file, and can hold many functions: area, wall_cost and room_cost are three functions in one file.
Good and bad points
| Approach | Good point | Bad point |
|---|---|---|
| Top-down | You see the whole plan. | You do not know the details at the start. |
| Top-down | Work is easy to share. | The plan may change. |
| Top-down | You are less likely to forget a part. | You test late. |
| Bottom-up | You start fast. | The parts may not fit the whole. |
| Bottom-up | You test small parts early. | You may build parts you never use. |
| Bottom-up | You reuse parts you trust. | The final plan may be unclear. |
| Modularisation | A module can be reused and tested alone. | Modules must join up with clear inputs and outputs. |
| Modularisation | A team can work at the same time. | Too many tiny modules are hard to manage. |
| Modularisation | A bug is easier to find. | A change in one module can break another. |
The cells students fill in are left blank in this preview.
Your turn: build from small tools
Build up from a small tool. area is built for you. Write wall_cost, which gives the cost to paint one wall: area times the price of one square metre. Then write room_cost for a room with four walls. Two walls are length by height. Two are width by height. Use wall_cost again. Press Run Tests.
def area(width, height):
# This tool is already built. Do not change it.
return width * height
def wall_cost(width, height, price):
# Cost to paint one wall. Use area(). price is the cost of one square metre.
return 0
def room_cost(length, width, height, price):
# A room has 4 walls: 2 of length by height, and 2 of width by height.
# Build it from wall_cost().
return 0
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.
Exit quiz
Have a go
Exit quiz
6 questionsRemember
Important
Top-down: whole to parts. Bottom-up: parts to whole. Modularisation: separate parts with one job each. Each has good and bad points.