DEV Community

Discussion on: Code readability metrics?

Collapse
 
ahferroin7 profile image
Austin S. Hemmelgarn

Various measures of complexity come to mind, as they're often used as guideposts for when to sub-divide functions for readability.

Cyclomatic complexity is the most commonly used one, and is essentially a measure of possible paths through the control flow graph of the code, typically measured per function/subroutine. Higher cyclomatic complexity usually translates to the code being more difficult to understand, and always translates to it being harder to test.

The other big one is the Halstead complexity measures, which reason about various properties of the code based on the number of operators and operands (both total and distinct values). They're somewhat harder to calculate in a lot of languages than the cyclomatic complexity, though the 'difficulty' measure is arguably more useful for deciding on readability than the cyclomatic complexity is.