6 ms·
Rust does have auto; "let" and function literal parameter type inference, for a start. It just doesn't let you use it in the return type position.
by EvenThisAcronym 6y ago
Rust does have auto; "let" and function literal parameter type inference, for a start. It just doesn't let you use it in the return type position.
- kibwen 6y agoThat's the salient point of this thread though; Rust doesn't have type inference in any position that shows up in API documentation. (The closest thing Rust has is return types of `impl Trait`, but even that imposes a contract that the caller must adhere to and that the callee cannot see through.)
- StillBored 6y agoWhich helps out the documentation side, but destroys code readability. Particularly since rust users appear to really like creating long method call chains, frequently with a closure or two sprinkled in. Take this "example" https://github.com/diwic/dbus-rs#server https://github.com/diwic/dbus-rs#server. For a beginning user of the library that is nearly impenetrable without breaking each of those calls apart. Even if your pretty familiar with rust you still have to break it apart and explicitly place the types in the "Let" statements to know the intermediate types in order to look up the method documentation. This style of coding is so bad, that it turns out the example has a syntax error. Good luck finding it without the compiler or a quality editor though. Worse, the example doesn't actually work due to further bugs. Anyway, rust by itself may be ok. Some of the core concepts are good, but the way people are using it is leading to inpenteratble messes of code. Code like the above combined with what seems excessive/unnecessary use of generics create problems for more advanced usage when it comes to learning and modifying a piece of code. Some people have blamed this on the language's learning curve, but I'm not sure that is appropriate. By itself the language is fairly straightforward, the difficulties occur when people are working around the language and pile in masses of write only code. That particular code block IMHO is why rust is going to have a hard time truly gaining widespread usage. Even as someone somewhat familiar with rust, moving the example into a program, and modifying it in fairly trivial ways took me the better part of a day.
- Rusky 6y ago> Even if your pretty familiar with rust you still have to break it apart and explicitly place the types in the "Let" statements to know the intermediate types in order to look up the method documentation. Maybe this is just me misreading your phrasing, but why would you actually have to break it apart into `let` statements? You can look up the types without modifying the program. Or are you talking about asking the compiler for the types with the `let _: () = ...` (or similar) trick? At that point you can just ask an IDE, also without modifying the program.
- steveklabnik 6y agoWhat’s the syntax error? I’m not a Linux user and there’s two different examples, but I am curious! Most code samples get automatically tested, but READMEs currently do not.
- fluffything 6y ago`auto` is just a keyword, that's used in D and C++ to implement many many different language features. Rust does not have fn foo() -> let { ... } where fn foo() -> let { 0_i32 } let x: i32 = foo(); fn bar() -> let { 0_f32 } let y: f32 = bar(); That is, you can't have an opaque function return type, that's both opaque, but simultaneously the user can name and use all interfaces from. If you change the implementation of `bar` with such a feature to return `i32` instead, all calling code of `bar` would break. And that's precisely why Rust doesn't have D/C++'s `auto` in return position.