4 ms·
Can't help but call out Rust here for it's (imo excellent) syntax. if condition {do_x()} else {do_y()} Basically there's no need for line breaks between if/el
by correct_horse 7y ago
Can't help but call out Rust here for it's (imo excellent) syntax.
if condition {do_x()} else {do_y()}
Basically there's no need for line breaks between if/else, but also they decided not to add a ternary conditional operator.
- ravenstine 7y agoif (condition) { do_x() } else { do_y() } That's the JavaScript version of what you wrote, and it's nearly identical. JavaScript doesn't require line breaks.
- kbp 7y agoThe significant difference is that in Rust, like in Lisp, `if` is an expression, so if-else essentially is the ternary operator. const x = cond1 ? a : cond2 ? b : c becomes in Rust let x = if cond1 { a } else if cond2 { b } else { c }