var r : i32;
How is this any better than int32_t r;
?
all I see is additional, unnecessary keyword to type. var r : i32;
How is this any better than int32_t r;
?
all I see is additional, unnecessary keyword to type. abc * xyz;
Depending on what abc is (variable or type name) it can be either a multiplication or pointer variable declaration. With the new syntax ambiguity is reduced.This might not be a huge issue for people reading code (because in context it should be pretty obvious), but for compiler it means that type information is required to parse code and compiler stages get mixed together.
let foo : & fn(&[MyType], i32) -> String = ...
(a reference to a function that takes a slice and a 32bit signed integer as arguments and returns a string)is dramatically simpler than the C/C++ equivalent.
More subjectively, I find `var` or equivalent makes code much easier to read, because you can scan for variable declarations much more easily. With C++ code, almost any token could be a variable declaration and you have to think about the type even if you wouldn't otherwise care about it. It also allows you to have inferred types without a separate auto keyword.
let foo : & (&[MyType] -> i32) -> String = ...
Like in Haskell? Seems having both `fn` and `->` is unnecessary? fn foo_bar(foo: &[MyType], bar: i32) -> String { ... }
so probably to match that.I believe Haskell does something clever such that there is no difference between a function that takes two parameters, and a function that takes one parameter and returns a function that takes the second parameter. This isn't the case in Rust. Those would be distinct types and the latter would be called differently to the former. So I'm not sure that the Haskell syntax would work for Rust.
On that note, is there any recently created programming language decided to go with that type before name?
For example "if the compiler can inherit the type" should read "if the compiler can infer the type".
The type omission version isn't very useful, as this type of code is difficult to read later. Generally end up regretting using auto, and end up converting it to the actual type, except with iterators or nasty templates.
Not to mention the weird appearance of uppercase letters in function calls (Print ?)