liveBook · Manning

Cyclomatic complexity

As explained in Functional Programming in JavaScript

A software metric that counts the number of linearly independent paths through a program’s control flow.

Cyclomatic complexity measures how many linearly independent paths can run through a program’s control flow. Conditional statements increase the number of paths that tests must consider.

Imperative versus functional code

The imperative showStudent implementation has cyclomatic complexity 4, while the functional implementation has complexity 1. Their complexity densities are 29% and 3%, respectively, alongside maintainability indexes of 100 and 148.

How Functional Programming in JavaScript covers it

How deep it goes
Defines independent execution paths and compares measured values, without deriving the metric calculation.
Examples
Uses the imperative and functional showStudent implementations and their metric comparison.
What you can do after
Evaluate implementations by comparing their control-flow complexity and related static metrics.
How it connects
Connects control flow, conditional statements, code coverage, functional programming, and maintainability.

Also explained in

Compare how 5 books explain cyclomatic complexity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Programming in JavaScript. The section links point to the parts of the book it draws on.