Cognitive Complexity offers a new measurement of how hard code is to understand - one that strikes developers as intuitively right.
This paper describes Cognitive Complexity, a new metric formulated to more accurately measure the relative understandability of methods. In doing so, it addresses the shortcomings of Cyclomatic Complexity in this area.
Cyclomatic Complexity uses a mathematical model to assess methods, producing accurate measurements of the effort required to test them, but inaccurate measurements of the effort required to understand them.
Cognitive Complexity breaks from the practice of using mathematical models to assess software maintainability. It starts from the precedents set by Cyclomatic Complexity, but uses human judgement to assess how structures should be counted, and to decide what should be added to the model as a whole. As a result, it yields method complexity scores which strike programmers as fairer relative assessments of maintainability than have been available with previous models.
Title: Cognitive Complexity™
Author: G. Ann Campbell