liveBook · Manning

Task

As explained in Get Programming: Learn to code with Python

A task is a unit of work performed through a sequence of actions or steps to achieve a goal.

A task is a unit of work performed through steps to achieve a goal. In programming, breaking a large task into smaller tasks makes problems easier to understand, test, and debug. section 20.1

Useful properties of tasks include:

  • A subtask should be self-contained, with clear inputs and outputs. section 20.1
  • A task depends on another when it cannot start until that task finishes. Independent tasks can happen at the same time or in either order. section 20.1
  • Choose reusable tasks without deciding their implementation too early. A task that reads one filename can be called repeatedly instead of being limited to two filenames. section 29.1

Ordering an item online

Ordering an item is one large task that can be divided into smaller ones: fill in the order form, extract the order details, find the item, make a shipping label, box the item, and send it by mail. Finding the item and making the label are independent. Boxing depends on finding the item, while mailing depends on both boxing and labeling. section 20.1

The same approach helps structure a document-similarity program: get and read a file, collect its words, count each word, and calculate similarity. These divisions describe the work without committing to specific implementations. section 29.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.

Trace how an online-ordering task becomes smaller reusable subtasks, with each gray box representing a task and surrounding items representing inputs and outputs. section 20.1

Figure 20.2. “Find in warehouse” shown with and without a black box over the task. Seeing the details of how the item is found and retrieved in the warehouse doesn’t add any more understanding of the task itself.

Compare a warehouse task with and without its internal details to see how treating it as a black box preserves focus on its role and outputs. section 20.1

How Get Programming: Learn to code with Python covers it

How deep it goes
Defines dependencies and independence, then stops before choosing implementations for the capstone tasks.
Examples
Uses online ordering and document similarity, including reading files, counting words, and calculating similarity.
What you can do after
Apply it by dividing problems into reusable tasks before selecting implementations.
How it connects
Connects tasks with subtasks, inputs, outputs, dependencies, independence, functions, and reusable design.

Also explained in

Compare how 12 books explain task →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Get Programming: Learn to code with Python. The section links point to the parts of the book it draws on.