3 ms·
> Edit: Plus it makes sense to have types after the variable name when they are optional in most cases (and then to have them in the same order in function sign
by twic 10y ago
> Edit: Plus it makes sense to have types after the variable name when they are optional in most cases (and then to have them in the same order in function signatures for consistency).
Since you brought this up, the one thing that really (but irrationally!) winds me up about Rust's syntax is that variables are:
let foo: Bar = ... ;
And functions are:
fn foo() -> Bar { ... }
Why not use a colon for the return type of a function as well?
- ordu 10y ago1. Rust mimics math notation. 2. If one needs variable to hold a function, he declares it like this: let foo: fn(i32) -> i32 = ... The second colon would be confusing.
- jomohke 10y ago"returns" and "is of type" are different concepts, so having different syntax for them makes sense. - In your first example, foo is of type "Bar" - In your second, foo is of type "function that returns Bar". ie, if you stored your foos in separate variables they would be: let my_var: Bar = ... vs let my_function: fn() -> Bar = ... If they were to change it to your suggestion the latter would be either awkward (multiple colons?) or inconsistent (different syntax for types and declarations).