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.
Big programdecompose→Split into sub-routinesshare out→Team members write the partscombine→Parts are joined and tested
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.
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-problem
Who
Why
Drawing the game screen
Nodira
she is good at design
Working out the scores
Ravi
he likes number work
Testing every part
Aisha
she 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.
Any two of: people can work at the same time; each part can be given to a specialist; small parts are easier to test; a sub-routine can be reused; mistakes are easier to find.
pack(4) returns 4 * 3, which is 12, so box is 12. The procedure label then prints Box of 12.
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.
One place if it is a function, because every call uses the same code. Five places if it was typed out each time, and one could easily be forgotten.
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.
Job
Best person
designing the screen
?
working out the scoring rules
?
checking every part works
?
Designing the screen: the design specialist. Working out the scoring rules: the number specialist. Checking every part works: the careful tester.