3 ms·
> Higher cyclomatic complexity requires more lines Often true; That's why cognitive complexity wins over cyclomatic complexity. eg: Embedded logic doesn't add
by imoverclocked 1y ago
> Higher cyclomatic complexity requires more lines
Often true; That's why cognitive complexity wins over cyclomatic complexity.
eg: Embedded logic doesn't add linearly.
fn() { // 1
if(...) { // +1
if(...) { // +2
if(...) { // +3
...
}
}
}
} // cognitive complexity of 7 vs cyclomatic complexity of 4
It's been a while since I've implemented anything around this and was remembering cognitive complexity while writing cyclomatic complexity in the previous response. They both have their place but limiting cognitive complexity is vastly more helpful, IMHO. eg: The above code might be better written as guard-clauses to reduce cognitive complexity to 4.
- gorgoiler 1y agoInterestingly, I read once that Hacker News moderators use a similar metric regarding the level of indentation in a thread. It’s a blunt tool to spot flame wars. More replying = more indentation = more heated = less interesting.