Hacker News new | ask | show | jobs
by dgellow 1513 days ago
Not for everybody, and I’m sure it’s not the most efficient way to approach it, but I personally felt that learning modern C++ was a good intermediate step before learning Rust.

Going to rust directly has been a very frustrating experience and made me give up.

Instead I spent time learning C++, I found out I could more easily transfer my knowledge/skills there. Once you become more proficient with the basics you learn about move, copy, smart punters, ownership, etc.

After some point you start to notice that you are basically doing in your mind exactly what a borrow checker enforce. So that made me curious and I tried rust again, and this time everything made complete sense and the language has been incredibly refreshing to work with.

This intermediate state was very useful for me to build my mental model and develop a better intuition, C++ made it simpler to do it in a more progressive way. And Rust is a fantastic langage if you can wrap your mind around it’s semantic and learn to work with the borrow checker.

3 comments

One reason C++ experience is so helpful with Rust is because the language was created by C++ programmers for C++ programmers, so most books and even documentation are written from that perspective.
This is something that's completely obvious to me. What I don't understand is why people online insist that Rust is so different and C++ knowledge is useless - I doubt I'd grok it immediately if I didn't understand C++.
> Going to rust directly has been a very frustrating experience and made me give up.

IMHO, you could learn Rust as a first PL by treating it as a functional programming language with a focus on purity, like a twist on ML or F#. The borrow checker rules and things like the String/&str distinction follow naturally from that POV. Then learn how "interior mutability" is used to enable more C-like procedural programming with shared mutable state.

I feel that by starting with FP, for example by starting with something close to ML in syntax and concepts, you cut yourself from too much of the programming world as everything else feels completely foreign and weird. But I get your point, you can approach it from the other side and also develop your intuition this way.
I had the same experience. Went to rust from a memory managed language, had no idea why people liked it so much. Then, I had to learn some Delphi (and not 10, like 7 compatible), and coming back to Rust was a breath of fresh air, and I understood the value in the ownership system.