Open Quuxplusone opened 15 years ago
Nikita: I recall us once discussing your interest in code metrics like this.
Absolutely. Code complexity metrics are useful in automatically detecting parts
of code which could benefit from refactoring and/or thorough code review. My
personal experience with cyclomatic complexity has been pretty positive - high
cyclomatic complexity values have correlated strongly with weak readability and
maintainability of the code.
I've implemented some very basic complexity metrics as additional clang checks
in my clang wrapper ([1], sample: [2]), but they're currently limited to
measuring complexity metrics of ObjC methods only. Would this type of
complexity analysis be sufficient, i.e. clang would generate a warning when a
certain method/function would exceed a single predefined, configurable maximum
complexity threshold value?
[1] http://www.karppinen.fi/analysistool/#complexity
[2] http://www.zhuk.fi/at/sparkle-complexity-scan-build-2009-05-06-2/
(In reply to comment #2)
> Absolutely. Code complexity metrics are useful in automatically detecting
parts
> of code which could benefit from refactoring and/or thorough code review. My
> personal experience with cyclomatic complexity has been pretty positive - high
> cyclomatic complexity values have correlated strongly with weak readability
and
> maintainability of the code.
Thanks Nikita. If you are interested, it would be great to include this as
part of the libAnalysis in mainline. Then others could expand its
functionality (and help maintain it) and different kinds of clients could be
constructed that used this routine (e.g., checks, IDEs, etc.).
a default cyclomatic complexity limit of 20 seems kind of high, Thomas Mccabe
recommends a limit of 10
http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/chapter2.htm#446033
It would be cool to be able to see a list with each row containing a module and
its complexity metrics. If we're limited to just having it report as a bug in
the existing static analysis report, it would be great to have the complexity
number somewhere in the message.
It would be really helpful if the static analysis tool could also calculate cyclomatic complexity. That metric is useful for identifying complex pieces of code that may be more error prone than others.