4 ms·
I feel perhaps you are missing my point -- you are talking about block separation and vertical space, I am talking about grouping of logical units. I agree wit
by sophacles 15y ago
I feel perhaps you are missing my point -- you are talking about block separation and vertical space, I am talking about grouping of logical units.
I agree with your points for functions, (most)loops, switches, and so in, but for if/else try/catch/finally do/while an other multiblock statements, I think it helps to have some convention to group them, other than indent level. The blocks depend on each other, not just are in proximity.
I would never do:
for (a;b();a++) {
stuff();
} if (test) {
...
}
because the if and the for are not parts of the same logical chunk. Nor would I do:
...
} else {
catchall();
} if (new_test()) {
...
Again because a new if is new logical chunk.
Basically, it isn't about block delineation or about vertical space, its about grouping logical units that have multiple blocks at the same nesting level.
- natesm 15y agoI use a newline and (sometimes) comments for that, so for example two unrelated if statements will have a blank line and some sort of comment between them. I think it would be really interesting to see how people's code style preferences translated to how they design things (or prefer designs). I like minimalism and lots of whitespace in designs, and it definitely translates to how I best read code.
- Jach 15y agoI follow Python's example for this. if (...) { ... } else if (...) { ... } corresponds to if ... : ... else if ... : ... not if ... : ... else if ... : ...