Cyclomatic complexity, sometimes referred to as McCabe's complexity, is a count of the linearly independent paths through source code. You can also think of this more simply as "the number of decisions a given block of code needs to make".
Most languages provide similar constructs (
while etc) for "decision" points. For a more comprehensive understanding of Cyclomatic Complexity, Radon, a static analysis tool which checks the cyclomatic complexity of Python code (engine), provides a bit more detail including the impact of specific statements on Cyclomatic Complexity.
Cyclomatic complexity measures the number of execution paths through code, but excessive return statements can make a function harder for a human to follow because control flow jumps around. So they are related, but different.
We recommend checking for cognitive complexity rather than cyclomatic complexity, and we pair that with a return statements check, as two of our 10 point maintainability inspection. (All of which is completely configurable).
Updated about a year ago