4 ms·
I think the author meant that we was abusing it: x = x ? (n ? m : w) : (b ? c : x); This doesnt seem too bad with variables, but now imagine this. int killMe
by cooervo 9y ago
I think the author meant that we was abusing it:
x = x ? (n ? m : w) : (b ? c : x);
This doesnt seem too bad with variables, but now imagine this.
int killMe = Factory.Omg ? (isFuckedUpped ? Leet.YES : Leet.NO) : (youGetTheIdea ? yep : nope);
- nerdponx 9y agoHonestly that looks perfectly readable to me. Easier to scan all at once, as opposed to several lines of an if-else block.
- falcolas 9y agoIt's not perfectly readable to me, I'd have to spend time stepping through both of these to ensure correctness. Who wins?
- nerdponx 9y agoJust so I understand, "correct" in what sense? That I got the right variables in the right place, or that there are no side effects, etc.?
- falcolas 9y agoAll of the above. More specifically, correct meaning that it's doing what it's supposed to be doing (and figuring out what it's supposed to be doing will take a few brain cycles too), and nothing more. My opinion is that code should be written in a way that makes it possible for an intern to read and update. I work with interns and fresh-out-of-college grads, and I need them to be productive too.
- tripzilch 9y agoTo be honest, I think nested conditionals of that form are hard to read whether you write them as if/else blocks or ternary expressions :) I'd first look for a way to try and avoid the whole situation, if possible. After that, what I feel is more readable depends on what formatting the language allows, length of identifier names, what the subexpressions look like, etc. Then, after careful consideration, I'll just follow any style guide and thus prefer if/else blocks, especially if a ternary would silently discard its result.
- TeMPOraL 9y agoWith slight reformatting: int killMe = Factory.Omg ? (isFuckedUpped ? Leet.YES : Leet.NO) : (youGetTheIdea ? yep : nope); it doesn't look bad IMO. Definitely more readable than if-else alternative.