liveBook · Manning

Cognitive load

As explained in Practices of the Python Pro

Cognitive load is the amount of mental effort required to understand or work with information or a system.

Cognitive load is the mental effort needed to understand or remember something. In software, reducing it leaves more attention for checking whether the program achieves its purpose. section 3.1.3

Reduce unnecessary cognitive load by making code easier to digest:

  • Abstract related code into functions whose names clearly state their purpose. section 3.1.3
  • Separate concerns into functions, methods, classes, or modules. section 11.5.1
  • Break dense expressions across logical lines, rather than obeying arbitrary line limits or compressing code. section 9.1.1
def valuable_customers(customers):
    return [
        customer
        for customer in customers
        if customer.active
        and sum(account.value for account in customer.accounts) > 1_000_000
    ]

Compare a compressed customer filter with a version that gives each condition room to form a mental model. section 9.1.1

How Practices of the Python Pro covers it

How deep it goes
Defines mental effort and applies it to naming, decomposition, and formatting, without measuring cognitive load directly.
Examples
Uses named functions, docstrings, a customer filter, and logically formatted multiline conditions.
What you can do after
Apply it via clearer abstractions, separated concerns, and readable formatting when improving software.
How it connects
Connects cognitive load with abstraction, encapsulation, separation of concerns, and maintainability.

Also explained in

Compare how 6 books explain cognitive load →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.