I am looking forward to master Rust in the coming 4-5 years.
I am looking forward to master Rust in the coming 4-5 years.
(I’m serious about this, as a user for eight years and casual trainer for several. The fact of the matter is that when the borrow checker complains, it’s right to complain, >99.99% of the time, even if you had thought carefully about it and were sure you got it right and that the compiler’s complaint was unnecessary.)
My personal recommendation to anyone just writing code as a learning exercise is that they start with using Rc<> wherever a borrow checker-related issue arises. Then you can get used to the rest of Rust. Once you feel a lot more proficient you can go back and start replacing Rc<> with references (and you might find that you don't even need to in many instances anyway)
But for the case where the data is modified, Rc often goes with RefCell as Rc<RefCell<X>> and allows in-place mutation called interior mutability. This means that the other code that got the copy of the Rc will observe the write effects.
I suspect this is because you naturally get to an instinctive form of ownership model similar to Rust. Since it is a really good way to reduce complexity. Rust then, merely formalizes and name it for you.
I feel like this verges dangerously close to patting ourselves on the back, but...
>I suspect this is because you naturally get to an instinctive form of ownership model similar to Rust.
I do feel this is more or less correct. I've only had a literal handful of "battles" with the borrow checker (over a couple months spent with Rust); the rest seemed to naturally parallel the ownership semantics I wanted in my code anyway. Ownership meaning everything from "where does a value arise" to "what parts of the code have access to that value in the first place". It forced - or rather nudged - me to think about my architecture in a way that led to a rather clear design, although it might have taken longer than in another language. In another words, I did move slower, but refactoring is much easier and less frequently needed, and that's a tradeoff I'm all for.
Compared to what? I have written about 10,000 lines of Rust so far... unfortunately, I stopped recently because I had a few huge refactors I had to make on one of my favourite projects which almost cost my sanity. The reason is that, in Rust, when you want to change the lifetime of a certain struct for example, you need to make sure that everywhere that's used it's only used in the new right lifetime... that turned out to be incredibly difficult to do and required heavy re-writing of many usages I had. Another huge refactor I had to struggle through was changing how I managed errors, and creating a new structure for my errors to be able to capture more information. Again, ran into huge issues which in a language with GC wouldn't exist. I still intend to go back to Rust as I do enjoy it even after all these issues I've had, but to claim Rust is easy to refactor strikes me as completely the opposite of the truth.