For 40 years, cyclomatic complexity has been the de facto standard for measuring testability and maintainability. While it’s absolutely accurate for testability, the same can’t be said for maintainability. Cognitive complexity solves the problem and returns “fair” relative measurements of control flow complexity.
In this session, you’ll learn what the cognitive complexity methodology is and why you should add it to your metric suite. You’ll see how it applies to a number of code samples from open-source projects on SonarCloud.io. And you’ll learn how to use a method’s cognitive complexity score as a guide to designing better code and refactoring existing code to be simpler and more maintainable.
Because there’s no “cost of entry” with Cognitive Complexity, a high cognitive complexity at the class level is a reliable indicator that a class contains a lot of logic, not just a lot of methods. That is, you can use cognitive complexity to sift POJOs from the logic-intense classes that impose a higher maintenance burden. Cognitive Complexity is available in most of the SonarQube ecosystem, but is an open standard, implementable by all.