3 ms·
Nitpick: I often break nested conditionals in several lines, like this: return a < b ? -1 : a > b ? 1 : 0; Reads like a switch state
by loup-vaillant 7y ago
Nitpick: I often break nested conditionals in several lines, like this:
return a < b ? -1
: a > b ? 1
: 0;
Reads like a switch statement, yet not overly verbose. I can parse it even more easily than the one liner.
Your point about "macro-readability" is spot on though. Nobody should care about the readability of an isolated piece of code. We should care about the readability of pieces of functionality and that generally requires understanding of a whole function, or even a whole class/module.
- Retric 7y agoUsing semantically meaningless structure is unlikely to survive being edited. if (a < b) return -1; if (a == b) return 0; return 1; Is simple boring code, has the advantage of looking odd when something odd happens.