Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

1.3 (1 of 3): Top-down, bottom-up and modules

The whole lesson, free. Read it and have a go at the activities. To work the tasks and labs in the real lesson, press Start lab, with no account needed.

40 minutes

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

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

WordWhat it meansExample
Top-downStart with the whole problem. Break it into smaller and smaller parts.Anna plans the whole video, then films each part
Bottom-upStart with small parts you can build. Join them to make the whole.Ben films clips, then joins them into a video
ModularisationSplitting a program into separate modules. Each module does one job.a login module, a payment module
ModuleA separate part of a program with one job.a file of functions
FunctionA named piece of code that does one job.def area
ReuseUse 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

A tree: School sports day app at the top breaks into Register runners, Run the races and Show results; Run the races breaks into Record the time and Work out the place, and Show results into Show the table.A tree: School sports day app at the top breaks into Register runners, Run the races and Show results; Run the races breaks into Record the time and Work out the place, and Show results into Show the table.

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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Each 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

Code: python
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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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

ApproachGood pointBad point
Top-downYou see the whole plan.You do not know the details at the start.
Top-downWork is easy to share.The plan may change.
Top-downYou are less likely to forget a part.You test late.
Bottom-upYou start fast.The parts may not fit the whole.
Bottom-upYou test small parts early.You may build parts you never use.
Bottom-upYou reuse parts you trust.The final plan may be unclear.
ModularisationA module can be reused and tested alone.Modules must join up with clear inputs and outputs.
ModularisationA team can work at the same time.Too many tiny modules are hard to manage.
ModularisationA 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.

Code: python
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 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Remember

Important

Top-down: whole to parts. Bottom-up: parts to whole. Modularisation: separate parts with one job each. Each has good and bad points.

Teach this lesson with your class

On a college account your students work the tasks and the labs as well, and every mark is kept for you.