Golfed code: nested ternaries, comprehensions with several for clauses, lines over 160 characters
Code longer than it needs to be: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as clever and dense-lines.
What makes golfed code a bad practice?
The standards that call it a bad practice: Google Python Style Guide: "Optimize for readability, not conciseness"; ESLint no-nested-ternary; Sonar S3358.
What does lessloc do about golfed code?
lessloc catches it as clever and dense-lines. The counterweight to simpler, so shorter never means cryptic.
clever(tier 2): Golfed code: nested ternaries, nested conditional expressions, comprehensions with severalforclauses.dense-lines(tier 3): Code lines over 160 characters, long strings and URLs aside.
Examples
Caught as clever:
ts
export const label = (n: number) => (n < 0 ? "neg" : n === 0 ? "zero" : "pos");Written well:
ts
export function label(n: number) {
if (n < 0) return "neg";
return n === 0 ? "zero" : "pos";
}Caught as clever:
python
def flat(grid):
return [c for row in grid for c in row if c]Written well:
python
from itertools import chain
def flat(grid):
return [c for c in chain.from_iterable(grid) if c]Related patterns
The other patterns in Code longer than it needs to be:
- Brute-force idioms: lessloc catches it as
simpler, built in for Python, JS/TS, Go, Rust, Java and C#. ruff (in every hook) and clippy (inci) go deeper. - Hand-built counters and flag loops: lessloc catches it as
simpler. - A catch that only rethrows: lessloc catches it as
simpler. - A promise wrapped in new Promise: lessloc catches it as
simpler. - Annotating types the compiler infers: lessloc catches it as
simpler. - A React Effect that only sets state from other values: lessloc catches it as
simpler. - Functions with many parameters (8 or more): lessloc catches it as
long-params. - Deep nesting: lessloc catches it as
deep-nesting. - Long functions: lessloc catches it as
long-function. - If-chains on literal values: lessloc catches it as
if-chain. - A file that keeps growing: lessloc catches it as
swollen-file. - Reformatting lines the task did not change: lessloc gives every session a rule against it and catches it as
churn. - Net growth past a budget: lessloc catches it as
net-growth.

