Code generation
Cyclomatic complexity / maintainability index
Implemented
code.code_complexityDefinition
McCabe cyclomatic complexity of each function (decision points + 1, counted as radon does) and the maintainability index MI = max(0, 100·(171 − 5.2 ln V − 0.23 G − 16.2 ln L + 50 sin √(2.46·rad(C))) / 171) from Halstead volume V, total complexity G, logical lines L and comment percentage C. Python source.
Formula
CC = 1 + decisions; MI as above
Range: CC ≥ 1; MI in [0, 100]
Inputs and outputs
- code: see the signature of es.code_complexity
Returns: MetricResult (value plus counts, intervals and breakdowns in params)
Assumptions
- Mean cyclomatic complexity per function over all programs (the value), with the maximum, the mean maintainability index and per-program results. Programs that do not parse are rejected.
Limitations
No metric-specific limitations are documented yet. Interpret the value alongside the task, data, and other metrics.
Python API
import evalsuite as es
es.code_complexity(["def f(x):\n return 1 if x else 0"])References
- McCabe TJ. A complexity measure. IEEE Trans Softw Eng. 1976;SE-2(4):308-320.
- Coleman D, Ash D, Lowther B, Oman P. Using metrics to evaluate software system maintainability. Computer. 1994;27(8):44-49.