Hi,
I read Ann's whitepaper a few days ago, and I must say I was immediately fond of it, so I just implemented it for perl. It's a so-called Perl::Critic rule [1], the perl-based linter tool. Unfortunately the sonar-perl plugin [2] cannot parse perl code yet, so I cannot yet import it as code metric, but only as "code smell". Still...
Alone the part about direct recursion seemed a bit arbitrary to me - given the fact that indirect recursion, the worse part of recursion, cannot be penalized at all. For example, most languages have other ways of iteration, take streams for example. When I announced that I will support the Cognitive Complexity model, I was immediately asked by one of my followers what kind of complexity this piece of code would be:
%params = map { $_, ( param($_) )[0] } grep { lc($_) ne 'submit' } keys param();
You all know that it's very easy to write perl code that is completely incomprehensible, so I wanted to check how the new scoring model works against this code. To the non-perlers, the code would literally translate into something like this in java-land:
Arrays
.stream(params())
.filter(p -> {return !"submit".equals(p.toLowerCase()); })
.collect(Collectors.toMap(Function.identity(), p -> params(p));
So, all in all everything but trivial, there's no nesting, and no boolean operators. What I'm saying is maybe the cognitive complexity may be missing on the fact that filter/grep like operations also act like if-else, and stream() is just a different way of iteration. Maybe this needs to be taken into consideration in a future iteration of the scoring.
Regards,
Oliver
[1]
https://metacpan.org/release/OTROSIEN/Perl-Critic-CognitiveComplexity-0.5[2]
https://github.com/otrosien/sonar-perl