Nice article, I would have chosen the following construct for the Rust example since pattern matching is more idiomatic in Rust than a bunch of if/else.
Its not quite as compact as your example but you can remove a level of indentation by just having one liners like x if x % 15 == 0 => println!("FizzBuzz"), if that's your thing.
One advantage to pattern matching in Rust is that it forces you to exhaust all possibilities when comparing values. This avoids forgetting the else or a particular case for a number.
Nice article, I would have chosen the following construct for the Rust example since pattern matching is more idiomatic in Rust than a bunch of if/else.
Something like this :
Its not quite as compact as your example but you can remove a level of indentation by just having one liners like
x if x % 15 == 0 => println!("FizzBuzz"),
if that's your thing.One advantage to pattern matching in Rust is that it forces you to exhaust all possibilities when comparing values. This avoids forgetting the
else
or a particular case for a number.Excellent article !
Thanks for sharing! I didn't actually write the FizzBuzz solutions, they are from a GitHub repo. I appreciate your input though, super useful 🤠
You should cite your source in the article.
Way ahead of you, I already did! It's in a comment in each snippet.