3 ms·
My first programming language was Python. And now I write Python and Go frequently. I'm trying to learn Rust, working through various programming exercises, bu
by clinta 7y ago
My first programming language was Python. And now I write Python and Go frequently.
I'm trying to learn Rust, working through various programming exercises, but it looks and feels very foreign to me.
One example is the closure syntax. Compared to Go where closures look just like function definitions, closures in Rust look needlessly complex.
I also always find myself wanting to type mut &a instead of the correct &mut a. The former just seems more obvious to me, a reference to a is &a. Mutable a is mut a. So a mutable reference must be mut &a.
Then the lifetime syntax, I don't even know what to think of that, but that's probably more because I'm struggling asking myself "Should I use a lifetime here, or am I doing something else wrong that is preventing the compiler from figuring it out."
Maybe these things make more sense to people coming from C.
- swsieber 7y agoI'm guessing the &mut a stuff makes more sense to C folks. In C you have to deal with const, and it can go anywhere. A const pointer to a non-const item, a pointer to const value, etc. That's my guess anyway.
- steveklabnik 7y agoWe took the closure syntax from Ruby/Smalltalk, and the lifetime syntax from OCaml.
- dastbe 7y agoOn &mut a vs. mut &a, when read literally left to right the former is “a reference to a mutable a” and the latter is “a mutable reference to a”