3 ms·
In that specific case, isn't it better style to write it differently anyway? Either: conditionWithReadableName: function() { return so
by vog 11y ago
In that specific case, isn't it better style to write it differently anyway?
Either:
conditionWithReadableName: function() {
return
someReallyReallyReallyReallyLongFunction()
&& anotherLongFunction();
}
...
while (conditionWithReadableName()) {
loopBody();
}
Or if you don't want to make up a good name for your conditional:
while (true) {
if (!someReallyReallyReallyReallyLongFunction()) break;
if (!anotherLongFunction()) break;
loopBody();
}
Or, in a more rules-based fashion:
conditionWithReadableName: function() {
if (!someReallyReallyReallyReallyLongFunction()) return false;
if (!anotherLongFunction()) return false;
return true;
}
...
while (conditionWithReadableName()) {
loopBody();
}
I find it troubling to make up "good" indentation rules when the code to indent isn't well-written in the first place. Multi-line conditionals are an anti-pattern in itself (no matter if they appear in "while", "if" or "for").
- ikurei 11y agoI agree with you in that multi-line conditionals should go, and no beautifier is going to make it up for bad code, but it's still great that they try. You can't always devote as much time as you'd like to make the code perfect, and that is when a beautifier comes the most handy. Also, having a good beautifier when you have to deal with other not-so-perfectionist programmer's code is great.
- vog 11y ago> having a good beautifier when you have to deal with other [...] programmer's code is great. Good point! I didn't think of that.
- philh 11y agoI'm not sure I like any of those as much as the original. When you introduce a new name, I don't know if you're going to use it anywhere else. (But having a name is good, so I'm on the fence.) When all your while conditions are inside the block, I have to actually look at it to figure out that it's really just a standard while loop.