4 ms·
I dislike the ternary operator in languages like C++. And many languages copy-paste it because they are used to it. I much prefer the more literal and reversed
by skocznymroczny 6y ago
I dislike the ternary operator in languages like C++. And many languages copy-paste it because they are used to it. I much prefer the more literal and reversed form in Python.
Instead of:
int salary = isEmployed() ? 2000 : 0
I prefer:
int salary = 2000 if isEmployed() else 0
- JimDabell 6y agoYes, it also makes the larger example somewhat readable: func calculate_tax(income): return 0 if income < 10 else 20 if income < 50 else 50
- jfkebwjsbx 6y agoI love that idea, but I still prefer it’d read the same as an if. Meaning the condition first and the false case last.
- nicoburns 6y agoRust implements this: let foo = if is_employed() { 2000 } else { 0 }