4 ms·
Yes, we do have Cyclomatic Complexity and it seems like that's it. Unfortunately, Cyclomatic Complexity is of dubious value. Even the wiki link you have here
by Verdex 5y ago
Yes, we do have Cyclomatic Complexity and it seems like that's it. Unfortunately, Cyclomatic Complexity is of dubious value. Even the wiki link you have here contains a section where they question the correlation between CC and the number of defects. Some studies say yes, but it looks like total program length is also correlated and sometimes better. Or in other words, line count might be a better metric than CC, which isn't exactly a ringing endorsement.
Additionally, even if CC turns out to be useful, it is rather targeted. Basically, it's a metric to make sure you don't have too many if-statements[1]. Not as effective in our current OO/FP world where lots of decisions can be shunted off to an unknown object or lambda.
However, whether or not you want to claim CC is useful for non-if-statement branches, it definitely doesn't say anything about code that's bad because of bad variable names, or code that's bad because of deep inheritance, or code that's bad because the wrong abstraction is used, etc (which is kind of what you're already saying with your statement about architectures and designs).
[1] - So, I guess you could probably create a CC setup that is able to count linear independent paths that aren't if-statement related. However, both OO and FP allow you to setup scenarios where the execution path indirection is decided at run time (pass in a different object implementation or a different lambda). So you crash head first into the halting problem pretty quickly. [Not to mention, I've never seen anyone try to do this ... although I haven't actually been checking very carefully, so maybe there are tools that try to do this in a limited fashion?]
However, it's also debatable which linearly independent paths are bad and which ones are actually helpful. Like, I bet that TCP library call contains a ton of linear independent paths. But if you fix that by just vomiting your hand rolled communication protocol onto the internet with objectively less linear independent paths, then I can't call that an improvement in program comprehensibility just because the linear independent paths have been reduced.