3 ms·
Syntactic sugar has been a big point of confusion in my path to learning Rust. Often I think I have understood something, try to verify by doing the wrong thin
by thomasahle 7y ago
Syntactic sugar has been a big point of confusion in my path to learning Rust.
Often I think I have understood something, try to verify by doing the wrong thing, but then because of sy tactic sugar it still works.
Two recent things come to mind:
- Automatic dereferencing, which can dereference arbitrarily long chains of indirection. This makes it hard to figure out which types I have.
- That `match` somehow accepts a reference to an enum, and then magically turns it into an enum over references.
Not that I don't think these will be worth it in the long run, but it makes the language harder to learn.
- _bxg1 7y agoYes. I've used Rust (in a hobby capacity) for a couple years now, I've written a fair amount of C++ and have a clear understanding of how pointers and references work, yet these two cases you mention sometimes remain mysterious to me. I've developed an intuition for "how to use them" but I don't always know exactly what they're going to do, because their meaning shifts under my fingers to try and match up with what's most convenient. I've just learned how to fiddle with them until the compiler accepts them. There's a fog over the code when they come into play.
- thomasahle 7y agoThere was also something odd about `Box<T>` automatically dereferencing, as well as `&&T`, but not `&Box<T>`. I can't remember if `Box<&T>` will dereference, which makes it feel like a set of arbitrary rules I just have to memorize.