AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Divide and conquer

Week 13 · 1.7 Software development · 3 lessons
2

Why share the work

Computing 8: Topic 1.7, pp. 150–172
GoalGive reasons why decomposition helps teams, specialists and reuse of sub-routines.
New words
team · a group of people who each work on a different part of the same projectspecialist · a person who is very good at one kind of jobreuse · using the same sub-routine again in more than one place
Explanation

Decomposition makes big projects possible. First, a team can work at the same time: each person takes one sub-problem and the parts are joined together later. Second, each part can go to a specialist. One person may be best at the screen design and another at the maths. Third, small parts are easier to test, and a mistake is found sooner. Fourth, a sub-routine can be reused. If a price rule is written once as a function, every part of the program can call it. When the rule changes, only one place needs to be edited. Without decomposition, one person would have to write, test and fix everything alone.

Worked examples
Python
1def add_fee(price):
2    return price + 2
3
4drink = add_fee(3)
5snack = add_fee(4)
6print(drink + snack)
Output
11
A function written once and used twice. add_fee is called for the drink and for the snack. If the fee changed from 2 to 3, the programmer would change one line instead of two.
Python
1def ticket_cost(adults, children):
2    return adults * 8 + children * 4
3
4def show_receipt(total):
5    print("Total:", total)
6
7cost = ticket_cost(2, 3)
8show_receipt(cost)
Output
Total: 28
A program split into two sub-routines, which two team members could write at the same time. The first function works out the cost, and the procedure shows it. The main program joins them.
Sub-problemWhoWhy
Drawing the game screenNodirashe is good at design
Working out the scoresRavihe likes number work
Testing every partAishashe notices small mistakes
Who does what? A team of three splits a game project. Each person takes the part they do best, and then the parts are put together and tested.
Class activity

Poster teams (no computer). In a group of three, agree on one big picture, such as a town street. Draw a quick plan, then give each person a part: buildings, vehicles and people. Agree the size of the pieces and where they go, because the parts must fit. Draw your parts separately on small sheets, then stick them together. What went well? Did parts fit? What would have gone wrong if one person had drawn everything alone, in the same time? If you have a computer or tablet, ask an adult to help you share one drawing job with a friend.

Practice
1
Give two reasons why a team splits a big program into sub-problems.
2
Trace the program. What is printed?
Python
1def pack(items):
2    return items * 3
3
4def label(n):
5    print("Box of", n)
6
7box = pack(4)
8label(box)
3
A shop program calls the same discount rule in 5 places. The rule changes. How many places must be edited if the rule is a function, and how many if it was typed out 5 times? Explain.
4
Match each job to the best person: designing the screen, working out the scoring rules, checking that every part works. People: a number specialist, a design specialist, a careful tester.
JobBest person
designing the screen?
working out the scoring rules?
checking every part works?