3 ms·
I can't see details of the Carbon syntax for pointer, array and function types, but this is where Rust's type syntax really excels compared to the C++ style.
by nicoburns 4y ago
I can't see details of the Carbon syntax for pointer, array and function types, but this is where Rust's type syntax really excels compared to the C++ style.
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.
- thomasahle 4y agoWhy isn't it let foo : & (&[MyType] -> i32) -> String = ... Like in Haskell? Seems having both `fn` and `->` is unnecessary?
- nicoburns 4y agoWell the syntax for declaring a function in Rust is: 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.
- nottorp 4y agoIt's definitely as hard to read as C++ though.
- nicoburns 4y agoI really disagree. Specifically when you have types nested within one another the complexity doesn't increase much. Whereas with C++ style declaration it quickly becomes type soup.