3 ms·
I think the most important lesson is this: Ownership is easy, borrowing is easy, what makes the language super hard to learn is that functions must have signat
by xiphias2 1y ago
I think the most important lesson is this:
Ownership is easy, borrowing is easy, what makes the language super hard to learn is that functions must have signatures and uses that together prove that references don't outlive the object.
Also: it's better not store referenced object in a type unless it's really really needed as it makes the proof much much more complex.
- echelon 1y ago> Ownership is easy, borrowing is easy 100%. It's the programmer that needs to adapt to this style. It's not hard by any means at all, it just takes some adjustment.
- geodel 1y agoIndeed. Programmers are holding Rust wrong.
- echelon 1y agoProgrammers new to Rust, you mean. It's kind of like career Java programmers using JavaScript or Python for the first time and bringing their way of doing things.
- cmrdporcupine 1y agoIt's more than that. Rust's value & reference passing semantics are completely different from the way most programmer's have trained their entire lives to think about it. When you pass an argument to a function in Rust, or assign a value into a struct or variable, etc. you are moving it (unless it's Copy). That's extremely different from any other programming language people are used to, where things are broadly pass by value pass by reference and you can just do that as much as you want and the compiler doesn't care. It's as if in C++ you were doing std::move for every single argument or assignment. And so as a programmer you have to shift to a mindset where you're thinking about that happening. This is profoundly unintuitive at first but becomes habit over time. Then having that habit, it's actually a nice reasoning skill when you go back to working in other languages.
- int_19h 1y agoI think sometimes that there's a niche for an alternative syntax for Rust that is generally more verbose (keywords instead of punctuation etc), and which specifically makes this behavior explicit. In other words, for every argument of every call you'd have to write "move" or "copy" and similarly with assignments etc.
- cmrdporcupine 1y agoRustRover recently added visual indication of the borrowing process within a block of code, which is kind of nice. I think for now it only shows for some cases and only when there's an error? but still you get a highlight of where the borrow happened so you can walk back to it and figure out how to fix it without having the parse through the compile error. I suspect they'll eventually get a fast and live indicator to the user of where all the references are "going" as they type.