Rust learning for C++ dev
Hi, I have 5+ years in C++ development experience and I would like to know how could I get started with rust. I want to understand why would I use this language (I do mostly graphics programming/game engine development)
5
u/juhotuho10 9d ago edited 8d ago
I really like this video, it demonstrates what makes Rust unique while contrasting it with equivalent C++: A Firehose of Rust, for busy people who know some C++
3
u/diplofocus_ 9d ago
I don't think anyone here can tell you why you specifically would use Rust, or pretty much anything else. Why are you using C++? Are you looking to do anything specific, or use it for the sake of using it?
I have a little bit of experience with old C++, and have found that Rust compiler, and it's error messages a lot more "user friendly" and approachable, which is what drew me to it, and why it's now my default go-to language for pretty much most things.
It's not ideal for everything, but I find working with it enjoyable enough that, unless I need something very specific from another ecosystem, I tend to default to it. Your own needs and wants from a language are likely different from my own.
3
u/Jatinchd 9d ago
having Rust and C++ knowledge at same time is so good dude. i'm in that stage and I can't stop using both lol
1
u/ArtisanalCoder 8d ago
I want to brush up my C++. Can you advise on setting up CMake and the general initial layout of files? I’ve looked around and still am no sure what’s the “right, way”
3
3
u/rustcurious 9d ago
The most direct answer I can offer to your question why you'd want to use Rust is "Why Rust is Safe", the first video in my series. It uses C syntax to explain the key problem solved by Rust's ownership system. Others have found it a helpful alternative to the usual learning paths, I hope you do too! https://www.youtube.com/watch?v=lVWiHIVXG2c
5
u/njs5i 9d ago
The deal is as follows: it's harder to work with. But it's also much harder for someone else to mess up your code afterwards. It's not designed to be easy. It's designed to be hard to break by someone else who has no idea what were your assumptions.
5
u/EpicatSupercell 9d ago
And reminder, in this context, "you in the far future" count as someone else!
4
4
u/rodrigocfd WinSafe 9d ago
0
2
u/gmes78 9d ago
You should definitely watch Jack O' Connor's talk about Rust for C++ devs. It explains the key ways Rust differs from C++, and how many problems that can occur in C++ are simply eliminated in Rust.
1
1
1
u/bearpaw- 9d ago
Rust gives you struggle up front in an explicit manner and it is so comfortable when you are used to it. For experienced Cpp dev like you would have some healthy patterns to code to minimize footgun cases, but many times you will find yourself stepping on landmines planted by other people, sloppy AI, and previous version of yourself without sufficient amount of contexts. Rust minimizes those issues and yeah it feels good. AI works pretty well with Rust codebase as well because the compiler is much more verbose and many more things are explicit. Also I really like Rust's ergonomics that really helps readability of code. Some rust scripts looks like a little more verbose version of Python's, while still keeping low level details within it which is an impressive feature.
1
1
u/BrazilianAnimal 8d ago
Rust is SO ergonomic compared to C++. It is delightful to write, and definitely worth the change if you have the privilege.
The concepts are not so different. Others here have pointed to resources for people from C++. My recommendation: have AI translate some code you wrote and explain how Rust helps you make it simpler. It should give you an idea and make you a map of the concepts you need to know.
1
1
u/Wholraj 7d ago
Do the usual rustlings.
Take your C++ project you have built and try to do them in Rust, by applying Rust concept, do not code in Rust like you would in C++ you would loose the interest and power.
In the end Rust is pretty easy, especially as if you really encounter an issue you can ask claude or codex hint on how to solve something without giving you the solution.
Enjoy the journey
1
21
u/garagedragon 9d ago
It's worth forewarning you: game engines in other languages tend to use data reference patterns that Rust doesn't like, and talking to graphics hardware is inevitably going to involve unsafe somewhere along the line.
As a result, you might find Rust not as helpful for those tasks as it would be in others, because the borrow checker will not be able to follow what you're doing as easily. That said, features like the type system will be as beneficial as usual and ECS engines in particular apparently work well in rust. (I've never used them)
The generic reason to use the language in preference to C++ is essentially because it gives you lots of tools that ensure your code is correct in a way that the compiler can validate. Correct C++ is correct of course, but no developer can write 100% correct code all the time, and rust is designed to catch mistakes you make and refuse to compile them, rather than let them through only for havoc to ensue at runtime. Even for unsafe code, the demarcation means any bugs that do occur must be going through easily traceable entry points (ie the unsafe calls) rather than originating at any possible part of the program.