4 ms·
Cyclomatic complexity is not equal to LOC and cyclomatic complexity of a switch can be seen as adding just 1 to its enclosing function. Either way, LOC is still
by imoverclocked 1y ago
Cyclomatic complexity is not equal to LOC and cyclomatic complexity of a switch can be seen as adding just 1 to its enclosing function. Either way, LOC is still not a great metric while cyclomatic complexity approaches a better one.
In my experience, there are very few places where something can't be broken up to reduce cognitive overhead or maintainability. When a problem is solved in a way as to make it difficult to do then maybe it's better to approach the problem differently.
- zdragnar 1y agoHigher cyclomatic complexity requires more lines (barring bad code style like writing an entire program on a single line). The inverse is not always true, but often is.
- 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.