3 ms·
honestly? i like it. properly formatted it looks alright: return ( (cellA === cellB) ? 0 : (cellA > cellB) ? 1 : -1 ); and it's an
by uryga 7y ago
honestly? i like it. properly formatted it looks alright:
return (
(cellA === cellB) ? 0 :
(cellA > cellB) ? 1 :
-1
);
and it's an expression, so i immediately know it won't do any weird control flow. i'd prefer "if/then/else" vs "?/:" but it's not bad
- mappu 7y agoThis works fine if the ? operator is right-associative, but in PHP it's left-associative and you have a subtle bug. I find a better indendation style for this is more like condition ? truthy : falsy
- uryga 7y agoi use that style too sometimes, depends on what's clearer. IME the former usually works better if you have a multiple tests, but the latter is the only readable option if you need to break a case across lines. yeah, ternary-if is busted in php :/ (far from the only thing that's busted there though...) i'm actually doing some PHP work right now, and never chain ifs to avoid this exact thing.