liveBook · Manning

Decomposition

As explained in Learn AI-Assisted Python Programming, Second Edition

Task decomposition is the practice of dividing a large problem or program into smaller, more manageable tasks or subproblems.

Task decomposition divides a large, underspecified problem into smaller, well-defined subproblems. Each subproblem becomes a manageable function, helping people control complexity, test behavior, and work effectively with AI coding tools. section 3.1 section 7.1

Use top-down design to turn an intimidating program into an organized set of solvable tasks:

  • Start with the overall problem and identify its major subtasks. section 7.1
  • Split any subtask that remains too large into smaller sub-subtasks until each task is simple enough for a focused function. section 7.1
  • Define each function’s inputs, return value, and single responsibility. section 3.8
  • Implement leaf functions first, then build functions that depend on them. section 7.7
  • Test every function with different inputs before relying on the larger program. section 3.8

Building a spelling-suggestions program

Instead of asking an AI assistant to create an entire spellchecker, define a main spell_check function and decompose its work. get_spelling_suggestions can create a word list, generate all possible edited words, filter those that are real words, and return unique suggestions. The generation step can split further into add_letter, delete_letter, and change_letter. Implementing the smallest functions first makes the larger functions easier for the assistant to write, test, and assemble. section 7.5 section 7.6 section 7.7.8

Figure 7.3 Functions diagram showing the three subtasks of get_spelling_suggestions
figure

A function diagram makes the hierarchy visible, showing how get_spelling_suggestions delegates work to smaller spelling-related subtasks. section 7.5

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Explains recursive top-down breakdown, function responsibilities, implementation order, and testing, while treating decomposition as a practiced design skill.
Examples
Demonstrates spelling suggestions, word searches, quarterback data processing, image merging, and order processing.
What it assumes
Assumes basic programming tasks and introduces functions, parameters, return values, helper functions, and unit testing.
What you can do after
Build it from scratch by designing function hierarchies, requesting focused AI-generated code, implementing dependencies bottom-up, and testing each function.
How it connects
Connects top-down design with functions, prompt engineering, unit testing, debugging, and software complexity.

Also explained in

Compare how 10 books explain decomposition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.