Rule 21 of 38 · Chapter IV — Write for the Next Developer
Optimize for reading, not writing
Why this rule exists
Code is read far more often than it is written — during reviews, debugging, extension, and the quiet re-reading you do to remember what you meant. A clever line that saves you thirty seconds today costs every future reader, including you, a minute each time they hit it. Optimizing for the writer is a false economy paid back with interest.
In practice
Prefer the clear version over the compact one: name intermediate values, split a dense expression into steps, choose the boring construct a newcomer will understand. When you catch yourself feeling proud of how tightly a line is packed, that is usually the moment to unpack it. Read your diff as if you'd never seen it, and smooth the parts that make you pause.
Example
return u.filter(x=>x.a&&!x.d).map(x=>x.id);const active = users.filter(
u => u.isActive && !u.isDeleted);
return active.map(u => u.id);When it doesn't apply
In genuine hot paths where profiling shows a real cost, readability sometimes yields to performance — but comment the trade-off so the next reader knows it was deliberate, not accidental.