Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Weirdly enough, as someone who actually really likes Python I hate its ternary, it's just an irritatingly inconsistent bit of syntax to conform to English.
-
Root825383yAlways, always, always use parentheses around your ternaries.
If you don’t, I will find you and I will stab you with your own keyboard. -
@Root I dont generally use nested ternary in C++. I only used it in Python because I was doing it inside a comprehension which has limited capability for code blocks.
-
Elvis operator FTW! That's also why you don't chain it. Rock'n'roll is not meant to be chained.
-
C0D4681463yNested ternaries and no brackets, do you want to be shot in the back, hung by the neck while I run barb wire over your back?
I don't care who you are, I'd print it out and slap you with it till you fixed it.
A single if/else ternary I can live with, but the moment it's anything more complex than that, it's not for a ternary to decide anymore. -
nibor48773yNested ternaries with no parentheses will fuck you up in c# thanks to ternary having same precedent as some other operators
-
Python does things for the sake of being "oh Im a different language compared to others, we do things the Python way and it's cool". When in fact it's not.
Related Rants
People hate on Python a lot. I just used the Python ternary operator for the first time. I found it easier to read than the C++ ternary operator:
0 if i==0 else 2 if i==segmentMax-1 else 1
vs
i==0 ? 0 : i==segmentMax-1 ? 2 : 1
I think Python did a good job in this case.
random
ternary
python