liveBook · Manning

Complexity

As explained in Grokking Simplicity

A measure of the difficulty of understanding or analyzing a piece of software based on its structure or behavior.

Complexity measures how difficult a software situation is to understand or analyze. With multiple clicks, queued actions and parallel AJAX callbacks can create several possible execution orderings. section 17.14

Timeline diagrams make the sources of complexity visible:

  • Parallel requests require multiple responses before the shopping-cart total can update the DOM. section 17.14
  • A queue handles rapid clicks, while Cut() separates the timeline into shorter portions that are easier to analyze. section 17.14
  • The remaining parallel area has two timelines and two possible orderings; later work proceeds sequentially. section 17.14

Two register requests

Calling countRegister twice starts two asynchronous requests that update a shared sum when their callbacks return. Their completion order becomes part of the behavior that must be checked. section 17.14

var sum = 0;
 
function countRegister(registerid) {
    var temp = sum;
    registerTotalAjax(registerid, function(money) {
        sum = temp + money;
    });
}
 
    countRegister(1);
    countRegister(2);

Inspect the JavaScript listing that launches two register-counting calls and exposes the shared-result interaction. section 17.14

How Grokking Simplicity covers it

How deep it goes
Works through timeline structure, parallel regions, and possible orderings, but does not provide the complete complexity formula.
Examples
Uses multiple shopping-cart clicks, two parallel AJAX responses, and two register-counting callbacks.
What you can do after
Diagnose asynchronous behavior by representing timelines, isolating parallel work, and counting relevant execution orderings.
How it connects
Connects asynchronous web requests, AJAX callbacks, queues, DOM updates, and timeline cuts.

Also explained in

Compare how 13 books explain complexity →

Related concepts

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