3 ms·
and yet people write: let result = if i % 15 == 0 { "FizzBuzz" } else if i % 5 == 0 { "Buzz" } else if i % 3 == 0 { "Fizz"
by Hello71 12y ago
and yet people write:
let result = if i % 15 == 0 {
"FizzBuzz"
} else if i % 5 == 0 {
"Buzz"
} else if i % 3 == 0 {
"Fizz"
} else {
i
};
in rust? either this is good, readable code or this is poorly written, unintelligible code. you cannot make the argument that sometimes it is readable and sometimes not based on the presence of braces.
- dbaupp 12y agoThe comparison is not "readable", it is "idiomatic". (I'm not saying either is unreadable, just pointing out that you're attacking the wrong thing.)
- burntsushi 12y agoUsing `if .. else if .. else` in Rust as an expression is absolutely idiomatic.