74 points by gone35 3 days ago | 28 comments | View on ycombinator
bunderbunder about 22 hours ago |
Deukhoofd about 12 hours ago |
I think generally when you run into something like this, the better way to handle it is to sit back, and reconsider how your overall handling is designed.
throwyawayyyy about 21 hours ago |
runningmike about 23 hours ago |
[1] https://nocomplexity.com/documents/codeaudit/complexitycheck...
Kim_Bruning about 10 hours ago |
I do agree you need to keep nesting depth down, because that really does break my brain.
But a long sequence of cases or elifs needn't always be a problem, and here they make it sound like it is.
ivm about 16 hours ago |
woggy about 23 hours ago |
Personally I have a some tools that build dependency graphs (C# and Python) and store the results in a local database. Agents seem quite good at poking at this and coming up with refactor ideas. Graph analysis tools are useful here, simple application will detect cyclical dependencies, but I encourage the agents to use more complex tools like clustering to poke at the data.
opsnotes80 about 19 hours ago |
That means that it really only counts explicit branching. So, for example, in an OO language like C#, calling a virtual method doesn’t increment cyclomatic complexity even though the method invocation could go down many code paths. Potentially thousands if you’re dealing with a common interface like IEnumerable. If you’re working on a library then the number of potential code paths in this kind of situation is unbounded.
As an aside, it’s interesting to think how it might apply to a language like Smalltalk that doesn’t even have if or switch statements.
OO isn’t the only monkey wrench, either. Higher-order functions also introduce forms of branching that cyclomatic complexity doesn’t measure.
Again that doesn’t make it a useless metric. Just don’t think that a cyclomatic complexity limit in your codebase is some sort of maintainability panacea. Some of the least comprehensible functions I’ve deciphered had quite low cyclomatic complexities.