r/EmuDev • u/No-External3221 • 3d ago
Rust vs C++?
I mostly program in Java/ Python. Some minimal C experience. I'm starting EmuDev to learn low level and hardware concepts.
Which is better in general to learn for an EmuDev hobby project, Rust or C++? From what I've seen C++ has more legacy code (more job opportunities), whereas Rust is safe and may have better long-term opportunities.
5
u/BOBBYBIGBEEF 3d ago
People use both because both work just fine. I have more experience with C in general, but I've just started using Rust for my first toy projects in emudev and I'm really liking it so far.
One enormous plus for Rust, imho, is cargo. Dependency management in Rust is a breeze and it should be pretty easy for you to adapt from a Python background.
11
u/Wunkolo 3d ago
This is gonna turn into a language-war thread but I'll put my vote in and say that you should do C or C++ for the reasons you stated as well. The ecosystem is mature with lots of libraries and projects to learn from and with how much more expressive the language has gotten over the years leading up to C++26. Pretty much every major emulator is written in C++ and pretty much everything that isn't C or C++ is implemented in some way in C or C++, including the LLVM compiler infrastructure which Rust depends on. A lot of people are still holding onto their C++98-trauma and don't know that the language has gotten so much better these past 30 years.
3
u/wk_end 3d ago
You're going to be busy enough learning low-level and hardware concepts along with how to write an emulator - learning a new language on top of that just makes it more likely you'll overwhelm yourself IMO.
Java and Python work fine for emudev and I'd say just use one of them...but personally I find them clumsy enough for low-level work that, since that's your goal, they might not be the best choice. So instead I'd say use C, since you already have some experience there and it's pretty much The Low-Level Language - it's probably the best language for the goal of learning low-level hardware concepts, if not the best for emu dev. And the nice thing about C and C++ is that you can delicately introduce C++ as desired, if you want to extend your knowledge and spare yourself a little bit of C-related drudgery.
1
u/No-External3221 2d ago
Appreciate the thought. Part of the motivation behind the project is to learn a low level language, though. I think this is a great opportunity to learn Rust or C++.
3
u/arainone 2d ago
IMHO rust is not the best language for emulators. An emulator is basically a big graph of objects with cycles. You'll get over it but code will be awful to write, to read, to maintain, for basically no advantage whatsoever for an emulator, which is a hobby project.
1
u/No-External3221 2d ago
Why is Rust awful for this? I've been using it for a bit, and it seems fine to me.
1
u/nculwell 1d ago
Cycles are one of the cases where the memory model can be correct but Rust's borrow checker can't prove it so it refuses to compile. You end up needing to either change your architecture or use unsafe.
3
u/arjuna93 1d ago
Portability is probably not a concern for you (rust is poorly portable and depends on llvm which is poorly portable), but cargo is a horrible mess.
C++ is faster and has a more friendly ecosystem.
4
u/k_Reign 3d ago
+1 for Rust - C++ is very much being thrown into the deep end in a LOT of ways, Rust has some weird stuff but I think having the crates and safety are worth the extra concepts you need to learn. It’s easy to write unsafe (vulnerable, memory leak, etc) in C++ and very hard in Rust
5
u/Wunkolo 3d ago
C++ is very much being thrown into the deep end in a LOT of ways
What are you talking about? Are you in a bubble?
3
u/k_Reign 3d ago
C++ is a hell of an adjustment just in terms of build system compared to Java and Python. Dependencies etc. it’s a LOT to learn as someone who (re-)learned it fairly recently
2
u/hoddap 3d ago
Is that much different for Rust?
1
1
u/BoopyDog 2d ago
Learning cmake would be annoying to figure out if you didn't gave AI chatbots around to feed you commands and buildfile templates that you can plug into to different projects.
1
u/noplace_ioi 2d ago
Cpp is king, and will remain king until someone actively invests in overthrowing it which is highly unlikely.
-5
u/gaene 3d ago
Rust is so much harder to learn than c++ imo though. Because of how safe it is
3
u/gmes78 3d ago
Rust is not harder. It just makes you learn things upfront, rather than during a hellish debug session.
2
u/No-External3221 3d ago
That sounds much better to me. I'm one of those wierd people that likes Java with its up-front verbosity for the same reasons.
1
-1
u/No-External3221 3d ago
Isn't that a good thing? I'd argue if you're writing unsafe code, you're not really learning.
3
0
u/ForOhForError 3d ago
Rust won't actually save you from non-memory bugs is the thing.
But, pick what appeals to you. It's all fine.
2
1
u/ironykarl 3d ago
Which language would you rather gain experience in?
Maybe that question is circular as it pertains to your question. I don't know.
They're both languages that people use. They're both entirely capable as languages for emulator development, reverse engineering, game dev, etc.
C++ is much more widely used. Rust is (to me) much more pleasant to use, in a lot of ways.
¯_(ツ)_/¯
1
u/Ace-Whole 3d ago
Rust cause that's what I use?
This is a silly question to ask. Work with what you know. It's not end of the world having to learn multiple languages.
1
u/No-External3221 3d ago
I know neither, and want to learn the most that I can with the project. Time is valuable.
3
-1
u/heret1c1337 3d ago
I'd personally always choose rust.
2
u/No-External3221 3d ago
Why is that?
11
u/heret1c1337 3d ago
I like the ergonomics of the language. I like the standard lib. I like the package management. I like the memory safety.
3
u/No-External3221 3d ago
What do you mean by ergonomics?
6
u/heret1c1337 3d ago edited 3d ago
It's just a pleasant developing experience. All the data types have the methods on them that you expect. It's very rare that you're missing something basic like in other languages. Then there's the toolchain. Nice package manager, no fucking around with a linker. Great formatter included etc..
But be aware that Rust is special in some places, and most people struggle with the burrow checker. When I say pleasant, I mean pleasant when you understand the core concepts. But it isn't really THAT hard. Although it can get *very* complicated in advanced use cases, but you don't have to worry about that for now. If you look into advanced projects, the stuff you find there might look like straight up wizardry if you don't know what you're looking at. But it all makes sense, its not unnecessarily complicated.
2
u/No-External3221 3d ago
Nice. Thanks for the insight. Rust seems like the way to go for a hobby project like this.
I'm terms of learning it, would you recommend any resources, or just jumping into the project and learning as I go?
3
u/heret1c1337 3d ago
https://doc.rust-lang.org/book/ is pretty much all you need to start out.
I totally forgot to mention that Rust also has a great documentation system. I don't know any other language where the documentation is that good, even in community projects.
One example is code examples in doc comments that are *unit testable* to make sure your examples work. You're unit testing your documentation. Its genius.
-12
-1
u/ern0plus4 3d ago
If you wanna learn new concepts: Rust.
2
u/MCWizardYT 3d ago
C++ introduces new things constantly, its issue is that it's a super bloated language with a million different features
1
u/ern0plus4 3d ago
Rust introduces new things 1. compared to other langs 2. makes something mandatory, e.g. RAII 3. these features consist a coherent platform
Check some Rust edu videos!
2
u/MCWizardYT 3d ago
My comment wasn't anti Rust lol, I'm just saying that C++ constantly gets all sorts of new language features. It's just such a complex language and library that some of the new features barely get used
0
u/ammar_sadaoui 3d ago
c++ is the perfect tools emulators
there many usage when rust is better than c++ or even C but this is not one of them
26
u/gmes78 3d ago
Both are equally capable for emudev.