3 ms·
that is a great idiom. i remember the first time i saw it (possibly in is very essay), i thought it was awesome. I use it all over the place now. it is similiar
by misiti3780 10y ago
that is a great idiom. i remember the first time i saw it (possibly in is very essay), i thought it was awesome. I use it all over the place now. it is similiar to the javascript ternary operator [1], which I also find to be very useful
var varX = (boolean) ? 'X' : 'Y'
[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Conditional_Operator https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- nommm-nommm 10y agoPretty much every language has a ternary conditional operator: C++, Java, Python, C#, Ruby....
- kevin_thibedeau 10y agoThis isn't the Python ternary which is: varX = 'X' if boolean else 'Y' # And is chainable in a more natural way than C*: varX = 'X' if boolean else 'Y' if other else 'Z'