cognitive complexity

Cognitive complexity is a software metric that scores how hard code is for a person to read and understand, based on control-flow breaks and nesting.

1 articleLast mentioned

Cognitive complexity is a software metric that expresses how difficult a piece of code is for a person to read and understand. It was proposed in 2016 by SonarSource, the maker of the static analysis tool SonarQube. The score increases for each structure that breaks the linear flow of code, such as conditionals, loops, and exception handling, with additional increments for deeper nesting.

Whereas the long-established cyclomatic complexity counts the number of execution paths, cognitive complexity is designed to reflect the difficulty a human experiences in understanding the code. It is typically measured per function and used to identify refactoring candidates or to set code quality thresholds.

This entry is based on AIPOST articles and widely known facts. If something is wrong, please send us a correction request.

Articles covering this entry

  • Example Mapping Plus TDD Lifts AI Agent Code Correctness From 27% to 94%AI in Practice ·

    The structured workflow cuts peak cognitive complexity by roughly two thirds, halves the longest function and pushes the mutation score close to the ceiling.

    Read article

Found a mistake or missing an entry?

Wiki entries are based on AIPOST articles and widely known facts. If an entry is wrong, send us a correction request and we will check and fix it. Names from new articles are added to the wiki after the article is published.