Chapter 11: Design

Some of this can be measured, which is useful for as long as you remember what the number is.

Cyclomatic complexity

Also called McCabe complexity

A count of the separate paths through a function: one, plus one for each fork, such as if, a loop, a case or &&. More paths mean more to understand and more tests to cover them.

It gives an agent a fast fact in place of an opinion about "too complex". It also has a blind spot you should know about: a lookup table scores 2 where the same logic as a switch scores 13, and that can be either a real improvement or a dodge.

Say it to your agent

“Add the ESLint complexity rule at 10 on src/, as an error. Where it fires, tell me whether the branches answer one question (leave it, and say why) or several (split it).”

The workshop

Name a word, or describe what you mean in everyday language.