Decomposition means breaking a big problem into smaller tasks you can handle one at a time. Before writing code, decide what the program should accomplish, what input it needs, and what output it should produce. Then look for smaller problems you can solve first. section 2.3
Start with the easy parts
Suppose a program must convert a number of minutes into hours and minutes. One task is to set up the input: `minutes_to_convert = 123`. Another is to show the result: print labels followed by `hours_part` and `minutes_part`. With input and output separated, you can focus next on calculating those two values. section 6.2
For a larger program, try this approach:
- Write down the main tasks without deciding exactly how to code them. A document-similarity program might read a file, get its words, count them, and calculate similarity. section 29.1
- Give each task a clear input and output. Prefer a reusable task that reads one filename over one that can only read exactly two. section 29.1
- Notice which tasks must wait for others. In an online order, finding an item and making its shipping label can happen independently after the order details are extracted; sending the package must wait for the packed box and label. section 20.1
- Check smaller pieces as they work, then put them together. A problem is less intimidating, and an error is easier to track down when you can focus on one piece. section 19.1 section 20.1
Figure 20.1. One possible way to divide the task of ordering an item online into smaller, self-contained, and reusable subtasks. Each gray box represents a task. Things to the left of the box are the inputs to a task, and things to the right are outputs of the task.
Follow the online order from task to task. Each box takes inputs on its left and produces outputs on its right, making it easier to see what must happen next. section 20.1
Quick check: If you were writing a program to process a list of words, what small task could you complete and check before tackling the whole program? Aim for a piece with a clear job that you could use again. section 19.1 section 29.1









