ALL-CONT0004 · deeply_nested_body
Whether one declaration nests bodies deeper than the ceiling a reader can hold.
This is a deterministic rule for all languages. Read its implementation.
Definition
Section titled “Definition”Walk the declaration and find the longest chain of constructs that open a body inside another
body, counting a branch, a loop, a guarded block, and a scope. Report the declaration when that
chain passes maximum_depth. Each level is a condition a reader has to carry from the line
that opened it all the way down, and by the fourth level the line in front of them only makes
sense together with three others somewhere above.
A construct only adds a level where it is written deeper than the one holding it, which is the
reader’s own measure since indentation is what nesting looks like on the page. That is what
keeps a chain of alternatives flat. Python spells the chain elif and hands over one branch,
while Rust and C spell it } else if { and hand over a branch inside a branch, yet both read
as one decision with several arms and neither costs a reader a level.
Nesting is also where bugs hide, because the deepest line is the one reached by the fewest inputs and therefore the one a test is least likely to run. The usual repair is a guard clause that returns early, or lifting the innermost body into a function that names what it does.
Continue with evidence and references, or open the examples.