Black for C++ proposes structured indentation so code layout mirrors its syntax tree
A developer found an ordinary C++ constructor initializer list hard to parse, needing several passes to trace its meaning. The article argues that conventional C++ formatting optimizes for column width rather than showing which parts of the code belong together. It highlights nested ternary expressions, where operators scatter across a line and obscure the structure. The author proposes four indentation rules that follow syntax, such as opening tokens ending a line and closing tokens dedenting. The proposed approach is demonstrated against clang-format on a nested lambda expression, with the aim of keeping code shape legible at any depth.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in