4

I've been using both CodeMaid and Resharper for some time now, and noticed they both calculate Cyclomatic Complexity. Although, their calculation always differ, so I'm thinking that their calculating logic also does. But, to your experience, which one is more accurate? It sseems that Resharper's is usually higher, but CodeMaid's is easier to spot.

Is one of them calculating it wrong, perhaps? Or just differently, but acceptable?

Thanks in advance!

1 Answers1

5

I can't speak to CodeMaid's implementation, but ReSharper's is based on parsing the source code into an abstract syntax tree, and actually building a control flow graph based on this information (this control flow graph is also used for null value analysis, tracing when things are null, not null or unknown, allowing for inspections such as "possible NullReferenceException"). I would expect ReSharper's to be an accurate calculation, but don't know for sure.

That said, as long as the difference between the values is fairly consistent, then it doesn't matter what the exact value is - just so long as you know what threshold means the code you have is too complex.

citizenmatt
  • 18,085
  • 5
  • 55
  • 60
  • 8
    As the author of CodeMaid, I agree with citizenmatt 's assessment. ReSharper's implementation is far more sophisticated than our own, which is a quick and dirty approximation based on detected keywords. With VS2015 and Roslyn now providing those metrics, it's in our backlog to leverage the new VS metrics and deprecate our own quick calculations. https://trello.com/c/wlC1l3RB – Steve Cadwallader Jan 29 '16 at 20:21