Cognitive Code Analysis is an approach to understanding and improving code by focusing on how human cognition interacts with code. It emphasizes making code more readable, understandable, and maintainable by considering the cognitive processes of the developers who write and work with the code.
"Human short-term or working memory was estimated to be limited to 7 ± 2 variables in the 1950s. A more current estimate is 4 ± 1 constructs. Decision quality generally becomes degraded once this limit of four constructs is exceeded."
Cognitive Complexity Analysis
java -jar cognitive-analysis.jar analyse ".\\src\\main\\java\\"
These pages and papers provide more information on cognitive limitations and readability and the impact on the business.
- Cognitive Complexity
- Cognitive Complexity Wikipedia
- Cognitive Complexity and Its Effect on the Code by Emanuel Trandafir.
- Human Cognitive Limitations. Broad, Consistent, Clinical Application of Physiological Principles Will Require Decision Support by Alan H. Morris.
- The Magical Number 4 in Short-Term Memory: A Reconsideration of Mental Storage Capacity by Nelson Cowan
- Neural substrates of cognitive capacity limitations by Timothy J. Buschman,a,1 Markus Siegel,a,b Jefferson E. Roy, and Earl K. Millera.
- Code Readability Testing, an Empirical Study by Todd Sedano.
- An Empirical Validation of Cognitive Complexity as a Measure of Source Code Understandability by Marvin Muñoz Barón, Marvin Wyrich, and Stefan Wagner.
- Halstead Complexity
- Cyclomatic Complexity
File: C:\Users\florian\Desktop\Java\cognitive-code-analysis\.\src\main\java\net\floriankraemer\cognitive_analysis\domain\ScoreCalculator.java
┌───────────────┬──────────────────┬─────┬─────┬──────────┬─────┬─────┬──────┬──────┬──────┬────────┬─────────┬──────────┐
│Class │Method │Line │ If │If-Nesting│Else │Loop │Switch│Method│Return│Argument│Try-Catch│Complexity│
│ │ │Count│Count│ Level │Count│Count│Count │ Call │Count │ Count │ Nesting │ │
│ │ │ │ │ │ │ │ │Count │ │ │ Level │ │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│ScoreCalculator│calculateScore │ 55 │ 0 │ 0 │ 0 │ 0 │ 0 │ 50 │ 0 │ 1 │ 0 │0,875 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│ScoreCalculator│getThreshold │ 3 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ 0 │ 0 │0,000 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│ScoreCalculator│getScale │ 3 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ 0 │ 0 │0,000 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│MetricConfig │getThreshold │ 3 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ 0 │ 0 │0,000 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│MetricConfig │getScale │ 3 │ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ 0 │ 0 │0,000 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│ScoreCalculator│calculate │ 25 │ 1 │ 1 │ 0 │ 0 │ 0 │ 10 │ 0 │ 2 │ 0 │0,182 │
├───────────────┼──────────────────┼─────┼─────┼──────────┼─────┼─────┼──────┼──────┼──────┼────────┼─────────┼──────────┤
│ScoreCalculator│calculateLogWeight│ 6 │ 1 │ 1 │ 0 │ 0 │ 0 │ 1 │ 3 │ 3 │ 0 │0,182 │
└───────────────┴──────────────────┴─────┴─────┴──────────┴─────┴─────┴──────┴──────┴──────┴────────┴─────────┴──────────┘
Copyright Florian Krämer
Licensed under the GPL3 license.