liveBook · Manning

Nonleaf function

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

A nonleaf function is a function that combines or coordinates multiple operations, often by invoking other functions.

A nonleaf function pursues one broader, clearly defined goal by coordinating multiple operations and usually calling other functions. Examples include updating game graphics or collecting and sanitizing user input. section 3.6.1

Design a useful nonleaf function by:

  • Giving it one particular goal rather than an assortment of unrelated tasks. section 3.6.1
  • Defining its behavior precisely; vague or subjective goals need clearer inputs, parameters, and outputs. section 3.6.1
  • Splitting complex work into smaller functions, then implementing leaf functions before the nonleaf functions that depend on them. section 7.7

Finding and removing a list value

Finding the largest value and removing it combines two operations. Make separate functions for finding and removing, then use a nonleaf function to coordinate them when the combined task recurs. section 3.6.2

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

How deep it goes
Explains design criteria and bottom-up implementation, but stops short of detailed code reading or full testing.
Examples
Uses game-graphics updates, input sanitization, spell checking, and finding then removing a list value.
What it assumes
Assumes the ability to divide an overall problem into subproblems while teaching how leaf and nonleaf functions relate.
What you can do after
Build it from scratch by decomposing a broad task, implementing smaller functions first, and composing them into a clear coordinator.
How it connects
Connects nonleaf functions with leaf functions, problem decomposition, parameters, docstrings, and testing.

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.