liveBook · Manning

Cognitive complexity

Cognitive complexity is the mental effort required to understand code or a system, particularly as nesting, control-flow breaks, or investigative paths increase.

How 2 Manning books explain it

The Art of Code

Cognitive complexity is a code-complexity metric that estimates the mental effort required to understand control flow, especially when flow-breaking structures and nesting are present.

How it is used
Identifies control-flow hotspots that undermine simplicity and readability, guiding targeted refactoring.
How deep it goes
Explains flow-breaking structures, nesting, Boolean conditions, per-method scoring, and refactoring strategies; defers functional-programming detail.
Examples
Uses email-reminder refactorings, stream pipelines, a SonarQube code smell, and a Kotlin promotional-message if/else chain.
What you can do after
Apply it via SonarQube or manual review to locate nested, flow-breaking methods and choose clearer refactorings.

Read how The Art of Code explains cognitive complexity →

Troubleshooting Java, Second Edition

The mental difficulty of understanding code investigation as the number of nested reasoning paths and open investigative plans increases.

How it is used
Guides code investigation when visible logic is insufficient to explain runtime behavior.
How deep it goes
Explains nested reasoning plans and investigation trade-offs, but stops short of formal measurement or debugging metrics.
Examples
Uses a Java Decoder method, StringDigitExtractor calls, and questions about returned digits and changed state.
What you can do after
Diagnose/debug with it by controlling investigation depth and tracing hidden behavior behind method calls.

Read how Troubleshooting Java, Second Edition explains cognitive complexity →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.