Are there any tutorials for C++ programmers?

I just found one tutorial that was wrote for C++ programmers, so C++ programmers could get Rust quickly.

Are there any other tutorials similar to this?

I went through my C++ to Rust transformation last year and I can't suggest tutorials but what helped me was to learn Rust basics and then watch some Rust expert code to learn what is the "Rust way" of doing things, how do they think about problems, etc. so that I don't force my potentially incompatible C++ patterns and habits into Rust programs.

Even though I didn't understand everything (and maybe even quietly disagreed with some approaches :slight_smile: ) it exposed me to different features of Rust, which feature to consider and when and it was good to compare what I thought was good and how they did it and learn why they did it their way. To me the value was all the talking about things, not necessarily the code itself. It's like watching a presentation vs reading slides -- I prefer the former when I don't know much about the topic.

There are many youtube/twitch coding channels now, back then I followed Jon Gjengset 's youtube channel, especially his early long coding videos.

2 Likes

To add onto this, using clippy is helpful for learning rust idioms.

3 Likes

I certainly recommend Jon's presentations.

And also those of Ryan Levick

Both excellent, although Jon is so turbo I find myself not keeping up, Ryan pitches things at a bit less expert level and slower pace which suites me well.

I have never been a sustained C++ user but I suspect that they might have a slightly harder time with Rust that I did from my C and mostly C-like language background. They have a lot more C++ baggage to unlearn :slight_smile:

I think one important thing is to actually read the Rust error messages properly. Unlike those of C++ they are very helpful. Unlike most languages it pays to have long conversations with the Rust compiler. In my case sometimes very long...

It seems to me that if you find yourself getting into a mess with lifetime annotations it's usually a message that one is tackling the problem the wrong way. It's possible to go a long way writing application code in Rust without a lifetime tick mark anywhere. Not so if one is getting down to writing ones own weird custom data structures though. Compare to the relative difficulty of writing and application in C++ vs writing the STL.

3 Likes

Also see: Rust for C++ developers - What you need to know to get rolling with crates - Pavel Yosifovich

1 Like

This one is good to start:
Learn Rust the Dangerous Way

3 Likes

The book Programming Rust (or the upcoming second edition) is not written only for C++ programmers, but it does include a lot of comparisons to C and C++ that I think make it especially useful for anyone with experience in those languages.

2 Likes

Thank you so much for your advice, your experience is so helpful. :smiling_face_with_three_hearts:

Yes, I usually spend a lot of time struggling with building errors. Thank you for your advice! :smiling_face_with_three_hearts:

Just learn syntax and start using Rust.

If you're good C++ programmer, you'll be good Rust programmer within month

Fighting compiler takes 2 weeks, then you get used to it

2 Likes

What does 2 weeks even mean? 5 days per week, 8 hours per day? That's what I'd consider as 2 weeks in Germany, if my task is to learn Rust as an employee. What I'm getting at is, 2 weeks is very subjective. Looking at the Rust survey is a great way to see how much time people spend on learning Rust. Some people only have time once per week or perhaps only in irregular intervals. Then there is individual skill and learning rate. 2 people might be equally skilled at programming in C++, yet one has an easier time acquiring new skills or 2 people might have differing skills at C++, but the less experienced C++ programmer is a quick learner. Sometimes, it depends on what kind of skill has to be learned.

In a nutshell, there are a lot of variables influencing how long it takes for any individual person to become a "good" Rust programmer. I'd avoid stating accurate timeframes, unless you're talking about averages taken from a representative statistic and trying to convince your boss to invest in Rust. It might discourage newcomers taking longer than expected.

My advice is, take the time you need, don't shy away from asking questions and don't forget the search functionality of the forum.

1 Like

I just found this great topic called Quick introduction to Rust for C++ programmers (my bad not search around in forum:( ), it has many wonderful advices. :metal:

On side note if you participate in C++ slack (cpplang) you can also find dedicated #Rust channel there.
A lot of people there have experience in both C++ and Rust

2 Likes

I just watched the video, it is exactly what I was looking for!

Maybe look at:

As a long time user of C/C++ and C-like languages, Pascal, Coral, PL/M, I find the entire notion expressed there totally backwards.

If C programmers are coming to Rust with the idea of wrapping everything they do in "unsafe" so that they can continue to write C in Rust syntax than there is no point in them adopting Rust in the first place.

Sure programmers of embedded systems will need "unsafe" to access their hardware. Sure "unsafe" is required if one want's to create one's own funky data structures.

But "unsafe" should not exist in application level code. Or at least very rarely.

As for "high performance" in my experience so far I have achieved the same or marginally better performance from Rust compared to the same algorithms written in C. Without using "unsafe". It's one of the first things I checked out in Rust so as to convince myself I was not backing a loser.

In short, those C programmers need the high-level nature of typical Rust tutorials.

The article does start with unsafe but it moves towards safe code with the safe code being faster than the unsafe code, which I think is an important point that is cool to have illustrated in a real example, especially to lower-level programmers outside of Rust who are often skeptical that safe code will ever be as fast as an unsafe language, not to mention faster:

2 Likes

I just read first 4 chapters, and it is so good, thanks for the great advice! :star_struck: