cogito, cognitive complexity for D

Eugen Wissner belka at caraus.de
Tue May 17 10:50:48 UTC 2022


Glad to announce that Funkwerk releases cogito [1], a tool that measures
cognitive complexity of D code.

>From the Sonar’s paper on cognitive complexity [2]:

“[…], Cognitive Complexity has been formulated to address modern
language structures, and to produce values that are meaningful at the
class and application levels. More importantly, it departs from the
practice of evaluating code based on mathematical models so that it can
yield assessments of control flow that correspond to programmers’
intuitions about the mental, or cognitive effort required to understand
those flows.”

cogito takes advantage of the DMD frontend (2.098.1 currently) to
analyze the D code. It was our first experience using the DMD frontend
for an internal tool.

Build and usage instructions are in the README. A pre-built version for
Linux x86-64 can be found in release attachments. You can build it
yourself with `make install && make build/release/bin/cogito`. There is
also a Dockerfile that can be used to run cogito, alternatively the
binary can be copied from the resulting Docker container and run on the
host system.

cogito reports the cognitive complexity of functions, aggregates and
modules. There are options to set a limit, so cogito fails if some score
is too high. The options are --threshold, --aggregate-threshold and
--module-threshold, respectively. On failure only the problematic units
are printed.

[1] https://github.com/funkwerk/cogito
[2] https://www.sonarsource.com/docs/CognitiveComplexity.pdf


More information about the Digitalmars-d-announce mailing list