3 ms·
fn add2(x: i32, y: i32) -> i32 { x + y } variable declaration is varname: type, it makes it very hard to read when declaring arrays or other things
by jokoon 7y ago
fn add2(x: i32, y: i32) -> i32 {
x + y
}
variable declaration is varname: type, it makes it very hard to read when declaring arrays or other things
return type is after the paren
the let keyword seems redundant/unnecessary, a little like var in js
Those are good example of "c flavor". I guess they're easier to parse, but still I would rather have C flavor instead.
- wtetzner 7y agoGotcha. I think with even a small amount of experience with the language, you'll find those things won't bother you anymore. I personally find the "varname: type" syntax easier to read. Also, keep in mind that Rust has type inference, so you can say things like "let foo = 37;", and the compiler will infer the type of "foo". The "varname: type" syntax is more compatible with optionally specified types, because it nicely fits in if you want to add the type info explicitly: "let foo: u64 = 37;".
- zozbot234 7y ago"Very hard to read"? As in, harder to read than the C declaration syntax for the same types? That's a logical impossibility!
- jokoon 7y agoSTL containers are pretty easy to read