Learning Rust
Looking around at the languages being developed and their communities, I think I’ve landed on the two languages I’m going to try to seriously learn and use over the next few decades. Those are rust and clojure. I’m just learning rust and it’s pretty great already. For example, here is FizzBuzz:
fn main() {
for n in range (1i, 101) {
print!("{}", fizz_buzz(n));
}
println!("")
}
fn fizz_buzz(num: int) -> String {
match num % 15 {
0 => { "FizzBuzz".to_str() }
5 | 10 => { "Buzz".to_str() }
3 | 6 | 9 | 12 => { "Fizz".to_str() }
_ => { num.to_str() }
}
}
#[test]
fn test_fizz_buzz() {
if fizz_buzz(2) != "2".to_str() { fail!() }
if fizz_buzz(3) != "Fizz".to_str() { fail!() }
if fizz_buzz(4) != "4".to_str() { fail!() }
if fizz_buzz(5) != "Buzz".to_str() { fail!() }
if fizz_buzz(15) != "FizzBuzz".to_str() { fail!() }
if fizz_buzz(16) != "16".to_str() { fail!() }
}
It would be nice if the testing facilities did a bit more on their own, but they are certainly nice enough.