3 ms·
> I'm pretty sure the compiler inferred a lot less back then (maybe 5-6 years ago now?) If it was post Rust 1.0 then it did not. The more likely case is the co
by masklinn 6y ago
> I'm pretty sure the compiler inferred a lot less back then (maybe 5-6 years ago now?)
If it was post Rust 1.0 then it did not. The more likely case is the combination of NLL and match ergonomics, which has made a lot of code way more comfortable, respectively by relaxing local borrows and avoiding a lot of minutia in pattern matches.
- nindalf 6y agoI understood the “inference” comment as “the Rust compiler is more helpful now”. Which it is. @ekuber and gang have put a lot of effort into better error messages over the years and continue to do so.
- codeflo 6y agoMatch ergonomics was one of the greatest improvements to the language, I’d personally put it almost on par with NLL. For anyone who’s interested: In Rust, you tend to do a lot of pattern matching and destructuring. But you also often only have a reference to your data, because copies can be expensive. Combining pattern matching and references was always possible, but confusing: you had to place lots of “ref” annotations in various places, which I never got right on the first try. But now, you can magically destructure e.g. a reference to a tuple into a tuple of references. You don’t have to think about it, it simply works. Combined with Rust’s algebraic types, this allows you to write very elegant, almost fp-like code that’s also zero copy.
- thomasahle 6y agoThose match "ergonomics" really tripped me up when first trying to learn Rust. I was trying to figure out references and deref, and I kept thinking I "got it" and trying to make sure by writing examples that should and shouldn't work. However, because of all the deref "ergonomics" magically spread around thinks like match, it was really hard to confirm whether I had the right mental model or not. Lots of things that surely shouldn't work somehow worked, and I couldn't explain why. I kept having to go to forums and people just told me "oh, this is a special magic case we added". Very frustrating.
- masklinn 6y agoYes, while "match ergonomics" made many "just work", the magic it implies also obscures the language, and code, a lot. I remain of two minds about it. If you want to make sure you have the right model you can always set edition to 2015 tho. You will also lose NLL and a bunch of other conveniences, but match ergonomics will be disabled.
- steveklabnik 6y agoNLL is in Rust 2015 these days. (As of Rust 1.36.)
- thomasahle 6y ago> If you want to make sure you have the right model you can always set edition to 2015 tho. That's a really interesting idea. I wonder if that would work well for teaching languages in general. Like teaching Java 1 instead of 16 where the language was much simpler.
- codeflo 6y agoI can totally see how this kind of convenience might hinder learning. For me, the fact that “&a” does so much magic type conversion stuff had a similar effect. One thing I sometimes find helpful is to run an IDE (like VS Code with the Rust Analyzer plugin) and hover over every single variable to see its type. Out of curiosity, since I expect to give a short Rust introduction in the near future, what was your language background when learning Rust? How familiar were you with C-style pointers and/or C++-style references?
- iudqnolq 6y agoA similar trick I learned from Jon Gjenset is to assert something has the unit type and read the error. let foo: () = complex_thingy();
- thomasahle 6y ago> Out of curiosity, since I expect to give a short Rust introduction in the near future, what was your language background when learning Rust? I have a background in lots of high level languages, like Python and Haskell, but never thought too much about how the types were represented. But prior to learning Rust I spent some time writing C (I've never done C++), so I guess I came in with a simple idea of how pointers work.