Top-down design starts with an overall programming task and progressively breaks it into smaller, well-defined subtasks. Each subtask can become a function with a small role, few parameters, and a useful result. This manages complexity, makes errors easier to locate, and gives AI coding tools smaller problems to solve. section 7.0 section 7.1
A practical top-down design process is:
- State the overall task and identify its input, processing, and output. section 7.4
- Split complex work into distinct subtasks, making each function responsible for a clearly defined behavior. section 7.1
- Continue dividing a subtask when its implementation is not straightforward; stop when the remaining work can be handled directly and clearly. section 7.5.2
- Experiment with alternative decompositions before settling on a design; no single breakdown is always correct. section 7.5
- Implement the resulting functions bottom-up, starting with leaf functions and then adding functions that depend on them. section 7.7 section 7.9
Spelling suggestions
A spelling-suggestion program begins as one large task: accept a possibly misspelled word and print corrections. Top-down design separates this into obtaining input, generating possible words, selecting real words, and producing output. Generating possibilities is divided again into adding, deleting, or changing one letter. The final spell_check function coordinates these smaller functions, while all_possible_words can call three helpers in a single line. section 7.3 section 7.5.2 section 7.7.5
Figure 7.4 Functions diagram with the three subtasks of all_possible_words added
The functions diagram shows the hierarchy from spell_check through get_spelling_suggestions and all_possible_words to the smaller letter-editing functions. section 7.6
The technique scales beyond spelling: it structures image-directory merging, games, and authorship identification. It remains an adaptable design activity rather than a rigid recipe; overly large functions, dozens of tiny functions, or excessive parameter passing can signal that a design needs revision. section 9.5.2 section 10.4.2 section 11.0

