3 ms·
I think previous experience programming in C++ can be helpful, in picking up Rust faster. For me, in large part, the borrow checker is encoding in the compiler
by jbandela1 3y ago
I think previous experience programming in C++ can be helpful, in picking up Rust faster.
For me, in large part, the borrow checker is encoding in the compiler rules that you should be following in C++ anyway.
A few hours debugging dangling references or iterator invalidation will make you appreciate what the borrow checker is trying to prevent.
You also have experience knowing the difference between pass by reference, pass by const reference, copy, and move.
Also, if you want to keep your sanity, you will learn to take ownership seriously. Deciding what owns what and whether objects will be owned by the scope (on the stack), be owned by unique_ptr, or be shared with shared_ptr is a large part of designing a C++ program.
Again these all map very neatly onto Rust idioms, and as a benefit are enforced by the compiler.
Coming from a garbage collected language where you previously did not have to care about things like that, and now, not only being forced to care, but having the compiler yell at you for every mistake can be a pretty big learning curve.
However, I would say that not knowing C++ doesn't mean that you can't learn Rust, only that it may take a little longer because you have to learn new concepts with regards to memory management and ownership, and so give yourself some slack and do not be discouraged.
- returningfory2 3y ago> For me, in large part, the borrow checker is encoding in the compiler rules that you should be following in C++ anyway. My experience was sort of the inverse of yours: I knew a little C++ before learning Rust, and being educated by the borrow checker has really helped me writing C++.
- mrtngslr 3y agoI've seen that too: having experience with Rust made C++ feel easy. I looked at C++ many years ago but never used it professionally. About 6-7 years ago, I learnt Rust and a few years later, I started working full time in a C++ team at Google. There are many things in the Google C++ Style Guide[1] that reminds me of Rust, from the ban on exceptions to the use of `std::optional` for optional inputs and outputs. [1]: https://google.github.io/styleguide/cppguide.html https://google.github.io/styleguide/cppguide.html
- dotancohen 3y ago> Also, if you want to keep your sanity, you will learn to take ownership seriously. Deciding > what owns what and whether objects will be owned by the scope (on the stack), be owned by unique_ptr, or > be shared with shared_ptr is a large part of designing a C++ program. I would love if you could expand on this. I've much experience with higher level languages such as Python, but as I get into C++ I find these nuggets of advise invaluable.
- brabel 3y agoI've found this Youtube video (and the whole channel) very good to help understanding Rust: https://www.youtube.com/watch?v=TJTDTyNdJdY https://www.youtube.com/watch?v=TJTDTyNdJdY Agree with the quote: that's the biggest challenge with Rust... I have been trying to pretend Rust is like Java and I think that was my big mistake. When you design anything in Rust, even the most basic stuff, you will need to decide "what owns what", unless you clone everything on every usage. Try some very simple code that requires allocation and you will quickly notice that. I am now back at Rust and redesigning all my code to make "what owns what" the first question I ask when writing anything, and that is already being very helpful. But of course: if you don't need the performance of Rust or the small footprint, it's just not worth it spending time on stuff like that can be completely and utterly ignored in any non-systems language.
- dotancohen 3y agoThank you.