5 ms·
Probably not. Although, you can immediately follow that up with asking whether this makes any sense in any programming language. From the wikipedia link: htt
by Verdex 3y ago
Probably not. Although, you can immediately follow that up with asking whether this makes any sense in any programming language. From the wikipedia link:
https://en.wikipedia.org/wiki/Cyclomatic_complexity#Correlation_to_number_of_defects https://en.wikipedia.org/wiki/Cyclomatic_complexity#Correlat...
Correlation between CC and defects isn't always present and in fact lines of code might be a better metric.
I assert that there is no current objective metric where you can plug in source code and get out some sort of comprehensibility value. Lines of code is the best we have at the moment. And it goes without saying (but I'm going to say it anyway) that lines of code isn't a great metric to be stuck with.
Right now the only thing we have are best practices (ie some other people were "successful" in some other context and they happened to be doing this) and code smells (right, the code makes my tummy feel bad, you can just feel the objectivity pouring out).
[It's been pointed out to me in the past that Weyuker's 9 Properties can be used to determine comprehensibility, but when you look at the papers published about it they're all really underwhelming. Basically, people have built a machine that when given source code dumps out a number that correlates to Weyuker, but then nobody takes the next step to see if that number actually correlates to anything that anyone cares about.
People are trying things though. For example, there's this:
https://www.sonarsource.com/resources/cognitive-complexity/ https://www.sonarsource.com/resources/cognitive-complexity/
I'm not particularly convinced by it, but it does a better job than Weyuker, iirc.]
- CharlieDigital 3y ago> I assert that there is no current objective metric where you can plug in source code and get out some sort of comprehensibility value. Ratio of ternary operators more than 1 level deep to total LoC. You know you're in for some pain when you randomly open a file and the ternary expressions go 6 levels deep.
- Verdex 3y ago> Ratio of ternary operators more than 1 level deep to total LoC. Sure. I should have said, "no current general objective metric". For example, if we detect any symbols longer than 6 billion characters, then we know the code is likely to be hard to grok. Or if the only character used in symbols is the underscore. And maybe the path forward for determining objectively comprehensible code is to collect every pathological case and then good code is code without the bad stuff. But I personally hope for a general solution that we can setup which will emergently determine that too many nested ternary operators is bad from first principles. I'm more than ready to be disappointed when this turns out not to be possible, but everyone is allowed a dream.
- bluGill 3y agoSure, but the vast majority of programmers don't do that type of thing. Often in cases like the above I'm not sure if the metric is correct - or is it just that you are not used to reading that style. For years I worked at places that banned the ternary expression and so I didn't use them and it was a lot of work to remember what was going on the rare times I saw them. Then I got a job on the team that did use them all the time (but never more than 1 level deep) and I soon learned to read them and now I use them often where they make sense.