Re:Rust for JavaScript Developers – Functions and Control Flow
by JimDabell on Monday July 06, 2020 @04:13AM
(#23745731)
Yes, it also makes the larger example somewhat readable:
func calculate_tax(income):
return 0 if income < 10 else 20 if income < 50 else 50
Re:Rust for JavaScript Developers – Functions and Control Flow
by jfkebwjsbx on Monday July 06, 2020 @09:11AM
(#23747487)
I love that idea, but I still prefer it’d read the same as an if. Meaning the condition first and the false case last.
Instead of:
int salary = isEmployed() ? 2000 : 0
I prefer:
int salary = 2000 if isEmployed() else 0