3 ms·
It's not perfectly readable to me, I'd have to spend time stepping through both of these to ensure correctness. Who wins?
by falcolas 9y ago
It'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.