liveBook · Manning

Flow-breaking structure

As explained in The Art of Code

A flow-breaking structure is a control-flow construct that interrupts straightforward sequential execution and requires reasoning about alternate execution paths.

A flow-breaking structure interrupts straightforward top-to-bottom execution and makes readers track alternate execution paths. Cognitive complexity measures this mental effort rather than merely counting paths for testing. section 3.1.2

Common sources of cognitive load include:

  • Loops, conditionals, exception handlers, mixed logical operators, and nesting interrupt the expected reading flow. section 3.1.2
  • Nested flow-breaking structures compound the burden because readers must maintain more possible execution paths. section 3.1.2
  • In Java scoring, each loop and each catch contributes one point; nesting increases the associated cognitive burden. section 3.1.2

Reminder-email validation

A reminder method combines a customer loop, active-customer calculation, several boolean conditions, email construction, and exception handling. Reading it requires following multiple possible paths, illustrating why nested flow-breaking structures raise cognitive complexity. section 3.1.2

Figure 3.2 Each flow-breaking structure (i.e., for, if, else) and each level of nesting increase cognitive complexity. In this example, the developer must keep track of several different execution paths to understand the overall logic.
figure

Use the diagram to trace how loops, conditionals, and nesting multiply the execution paths a reader must keep in mind. section 3.1.2

How The Art of Code covers it

How deep it goes
Defines the reading-flow problem and gives Java scoring examples, but stops short of a complete scoring specification.
Examples
Uses a reminder-email method and a diagram showing loops, conditionals, nesting, and multiple execution paths.
What it assumes
Assumes familiarity with Java loops, conditionals, logical operators, and exception handling.
What you can do after
Evaluate code by identifying structures that increase reader effort and by recognizing the effects of nesting.
How it connects
Connects cognitive complexity with cyclomatic complexity, nesting, logical operators, loops, conditionals, and exception handling.

Related concepts

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