Monotonic Indentation
- 440 words
- 2 minutes to read
- comments
People have been arguing about how to indent code for as long as there’s been code, and nobody has settled it. Java’s Checkstyle aligns continuations under the open paren, ESLint and Prettier each invent their own rules, Go’s gofmt uses tabs and shrugs, RuboCop hands you a menu, Python’s PEP 8 picks four spaces and leaves the rest to taste. Every tool has its own dialect, and teams waste hours fighting over the details. I suggest a simple rule of monotonic indentation for source code of any programming language:
Between any two adjacent lines, indentation may increase by exactly one unit.
This rule should resolve most disputes about code formatting style. It is easy to add as an extra check to any existing style checker, or to deploy on its own as a small standalone tool.
