Content Deep Dive
Cognitive Complexity, Because Testability != Understandability
Blog post from Sonar
Post Details
Company
Date Published
Author
G. Ann Campbell
Word Count
1,069
Language
English
Hacker News Points
-
Summary
SonarSource is introducing `Cognitive Complexity` as an alternative to `Cyclomatic Complexity`, which measures testability, but not maintainability. Cognitive Complexity aims to provide a fair representation of how difficult control flow in a method is to understand and maintain. It increments for structures that break the linear flow of code, nesting, and ignores "shorthand" structures. The new metric is designed to incent good coding practices by penalizing complex constructs and ignoring readable ones. Cognitive Complexity will be added as a method-level rule in mainline languages, initially starting with Java, JavaScript, C#, and C/C++/Objective-C, with the goal of eventually adding class/file-level rules.