rust is pretty good

rust is a pretty good language. this is not a controversial point at all, it was labeled one of the most loved languages by the survey everyone points to to say rust is pretty good. but one of the things i love most about it is the (sort of trivial) things it gets right that not many other languages have, despite them being pretty obvious in hindsight.

blocks return values

this is a thing where i don't understand why almost no other language doesn't do it. probably something about the distinction between expressions and statements and that C defines a block as a statement which contains a set of statements, and statements don't return values. this is a fairly arbitrary decision but since so many languages are based on C in some way it's been the norm in languages for quite a long time. this results in some sort of hacky things, like the , operator which takes two expressions and returns the second, for things like this:

int c = 0;
if(c = 5, c % 2 == 0) printf("this won't print\n");

in rust you can do things like this:

let c = 0;
if { c = 5; c % 2 == 0 } {
  println!("this won't print");
}

cc0 everything on this site is freely available under CC0 1.0 Universal.

home blog