Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

cyclomatic complexity #4634

Open Quuxplusone opened 15 years ago

Quuxplusone commented 15 years ago
Bugzilla Link PR4160
Status NEW
Importance P enhancement
Reported by c t (chris@bluelavatech.com)
Reported on 2009-05-05 22:33:30 -0700
Last modified on 2016-06-19 08:55:18 -0700
Version unspecified
Hardware Macintosh MacOS X
CC fang@csl.cornell.edu, kremenek@apple.com, llvm-bugs@lists.llvm.org, llvm@georg.so, nikita@zhuk.fi
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

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.

Quuxplusone commented 15 years ago

Nikita: I recall us once discussing your interest in code metrics like this.

Quuxplusone commented 15 years ago
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/
Quuxplusone commented 15 years ago
(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.).
Quuxplusone commented 15 years ago
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.