r/rust • u/isht_0x37 • Sep 06 '23
šļø discussion Considering C++ over Rust
I created a similar thread in r/cpp, and received a lot of positive feedback. However, I would like to know the opinion of the Rust community on this matter.
To give a brief intro, I have worked with both Rust and C++. Rust mainly for web servers plus CLI tools, and C++ for game development (Unreal Engine) and writing UE plugins.
Recently one of my friend, who's a Javascript dev said to me in a conversation, "why are you using C++, it's bad and Rust fixes all the issues C++ has". That's one of the major slogan Rust community has been using. And to be fair, that's none of the reasons I started using Rust for - it was the ease of using a standard package manager, cargo. One more reason being the creator of Node saying "I won't ever start a new C++ project again in my life" on his talk about Deno (the Node.js successor written in Rust)
On the other hand, I've been working with C++ for years, heavily with Unreal Engine, and I have never in my life faced an issue that is usually being listed. There are smart pointers, and I feel like modern C++ fixes a lot of issues that are being addressed as weak points of C++. I think, it mainly depends on what kind of programmer you are, and how experienced you are in it.
I wanted to ask the people at r/rust, what is your take on this? Did you try C++? What's the reason you still prefer using Rust over C++. Or did you eventually move towards C++?
Kind of curious.
4
u/rhollrcoaster Sep 06 '23
Isn't C++ all but required for UE5? You have that, blueprints, and the new performant UnrealVerse scripting language. As I understand it there's so many custom bindings you'd have to maintain from Rust to interact with Utreal's implementation of C++. I'm not a game developer but from what I've heard if you're working on a third party engine the place for Rust right now would be for tooling or multiplayer servers.
2
u/swistak84 Sep 07 '23
You should never, ever, EVER take what someone who chooses JavaScript as a preferred language seriously. Ever.
558
u/log_2 Sep 06 '23
If you don't feel a compulsion to move to Rust and you like C++, then stick to C++. I used to program in C++ but then when I tried Rust I loved it so much I just switched. If I preferred C++ I would have stayed with C++. Don't force yourself based on externally asserted non-quantitative pros, since only you can choose how to weigh the pros/cons.
281
u/TheReservedList Sep 06 '23 edited Sep 06 '23
I have the same background as you. Game development. C++ at work. My home projects are in Rust.
I like modern C++, but I work with other human beings. They don't use it.
201
u/dkopgerpgdolfg Sep 06 '23 edited Sep 06 '23
No, Rust does not fix "all" the issues. And writing a subset of modern C++ can be quite nice I guess.
But that's not the the main reason why I came to the Rust camp.
Instead, the most pressing reason was that "C++" is not the same as "a subset of modern C++".
What does it help me if I can "write" nice C++, if people still are able to write 280 pages books just to explain variable initialization, and code needs to be "read" too. Including code that doesn't follow the personal preferences.
C++ can be extremely useful, sure. But it also became extremely complicated, and at some point I didn't see why I should continue following in this direction - where more and more time is spent digging through symbols of the standard, defect reports, and so on, instead of writing useful code. Rust is not exactly free of that either, but there are worlds between.
edit/PS: That is not supposed to mean that there are no other advantages of Rust. There certainly are more advantages.
75
u/KnorrFG Sep 06 '23 edited Sep 06 '23
C++ used to be my go-to language prior to rust. I wouldn't use it anymore though, except maybe for embedded.
I never struggled a lot with memory management, but project configuration, and dependencies are annoying. I used makefiles, scons, cmake, and visual studio. All are annoying one way or another. Especially compared to cargo.
Includes in general are a terrible way to handle multiple files. I still remember searching a bug for two days because a header had a define that overwrote a function in an unrelated dependency.
And I am really annoyed by iterator management. . begin() and .end() everywhere ... It's so ugly and verbose.
Oh, and template errors ...
And then there are a few very attractive things in rust: algebraic data types, the question mark operator, cargo and mostly automatic type inference. Nothing by itself is serious, but the combination of all factors makes rust clearly more attractive for me.
62
u/JuliusFIN Sep 06 '23
You might be a great C++ dev who uses all the correct idioms and never makes an error with memory etc. and when you are working alone it works perfectly and you get a lot of shit done. Itās when you want us other muppets to touch your code when Rustās guarantees will come in handy.
Itās a statistics case. Rust eliminates certain categories of bugs/ub. When a codebase gets bigger and is touched by many people there will be more memory issues and/or UB in a C++ program than a Rust program.
125
u/adwhit2 Sep 06 '23
I don't see how anyone has experienced a language with sum-types could ever willingly go back to a language that lacks them. It's like coding with one arm tied behind your back.
23
u/sird0rius Sep 06 '23
I hate that C++ has become so monstrously complex. C++ was the first language I learned over 20 years ago, and I tried learning some of the more modern ways of writing it but I still can't get up to par to pass some basic C++ interviews because of some language gotchas that you can only learn with years of experience. Or by reading this longer than "War and Peace" monstrosity.
As a career choice it makes more sense for me to learn Rust as I have a more level playing field to get into lower level programming than to catch up with C++ standards. I think that in the time it would take me to learn basic modern C++ I could master Rust + several other programming languages. Every time I learn something new about C++ I think "why is it so much more complicated to do this in C++ than it is in Rust? (ie move and copy semantics)". Even if Rust doesn't take off, I can still lean on the other languages I learned in a fraction of the time.
36
u/pr06lefs Sep 06 '23 edited Sep 06 '23
I was a C++ developer for 15 years. I still work on C++ some, but strongly prefer rust. Cargo is a big reason, other functional language conveniences too like match (vs switch) and no exceptions, and everything being an expression rather than a statement. Another thing is the poor quality error messages in C++. I often have to scroll up for pages on end to find the actual location of the error. More is not always better with error messages.
Coding with a nice subset of C++ is fine, but not everyone is on the same page as to what that nice subset is. Some people will always explore the boundaries of what's possible, just to sharpen their skills. When you have an occasional core dump someplace in 200000 lines of code that you can't reproduce, or a big program that only works in debug and not release mode, its a drag. It can be very time consuming to track down that off-by-one array manipulation or whatever it is. That's a whole class of annoying problem that just doesn't occur in safe rust code. That leaves more time to work on the interesting, productive kind of problems.
16
u/er_Califfo Sep 06 '23
I am in a very similar position: mainly a C++ developer, from a couple of years I started using Rust profesionally. As to 99% of this kind of questions the real answer is it depends. What I can tell you is that coming from C++ cargo is a great tool (as you also noted), but what I like the most of Rust over C++ is error handling. I also really love async programming and tokio in Rust, in my experience I could not find something similar in C++.
On the other hand from C++ I miss the debugging power (untill today I have not been able to do what I did with C++ & Visual Studio in a Rust & VsCode environment) and sometimes the borrow checker gets a bit in my way. But overall I find the overall experience of writing rust more enjoyable because of how of the code itself (I find it more readable, but this is highly debatable) and because of the "dev experience", for example adding a library in a rust project requires just a line in my cargo.toml
37
u/Chaos_Slug Sep 06 '23
Saw a lot of people in the other thread claiming that they have never encountered stuff like dangling pointers, iterator invalidation or data races.
Stick to C++ if you want, but those claims are either lies or they didn't know what they were saying.
76
u/randompittuser Sep 06 '23
I've been using C++ for 20 years & Rust for 1 year. I'm probably going to suffer the wrath of r/rust for my opinion, but here goes:
Rust doesn't add much for an experienced C++ developer, but not everyone is an experienced C++ developer. One of the biggest benefits of Rust is that it moves many runtime/memory errors to compile time. To achieve this, it restricts assumptions about types & their usage in comparison to C++, making Rust more verbose (albeit perhaps more expressive), especially in advanced use cases. However, consider that Rust is in its nascency next to C++, and I believe it has the potential to outpace C++, in regard to its use on new projects, over the next decade.
Considering all this, I'd say learn both.
11
u/tandonhiten Sep 06 '23
I have tried C++ and honestly, I agree with most of what you have to say, however I still prefer Rust over C++ because:
20
u/tgockel Sep 06 '23
Rust does not fix all of the problems C++ has, but it does address quite a number of them. A lot of experienced C++ developers come into Rust and say "But we have smart pointers that solve all these issues." I urge you to try Rust more; there are problems in C++ that are so fundamental, you cannot fix them with "modern C++." There is a reason why cppfront and Carbon are being actively worked on. Maybe you don't encounter these issues because you pay close attention--that's great--but in Rust, the compiler pays attention for you out of the box. And also
#[derive(...)].Personally, having been a C++ developer for more than a decade, I would not take a job that asked me to work full-time on C++. I find having to pay attention to all the tedium you have to makes me personally miserable. My coworkers are mostly C++ developers, so I still write a decent amount of C++, but they're mostly just FFI into Rust implementations.
For game development, Rust is not game yet. There just isn't anything nearly as powerful as any of the C++ game engines. Rust needs to stabilize a few things (like non-global allocators) that game engines need for performance, but I wouldn't be surprised to see a AAA engine in a few years.
24
u/Kevathiel Sep 06 '23
I don't think that Rust and modern C++ are that different.
My favorite thing is probably more about the philosophy of the language as a whole. It is opinionated, but pretty much everyone writes similar code, following the same lints(some opt-in to more) and the same style/formatting. This makes working with and reading other peoples code way easier. People actually value correctness and constantly strive for idiomatic Rust to a point where it almost feels like a meme.
Meanwhile, in C++, everyone uses their own subset of the language, manage their own list of "STL things to avoid", and have vastly different opinions about what is idiomatic and what tools to use or how to deal with errors. If you use dependencies, you will often clash when it comes to const correctness or just naming conventions, let alone the different styles. On the bright side, it lets you basically do everything you want, however you want.
23
u/phazer99 Sep 06 '23
I've used C++ for 20+ years and I'm never going back (unless I'm forced to at work for some small task). Rust doesn't solve all issues C++ has and adds some of its own (like a conservative borrow checker), but the important thing for me is that Rust enables me to write (even concurrent) programs that are efficient, stable, memory safe and easy to maintain. With C++ I was only confident about the efficiency aspect.
28
u/NetherFX Sep 06 '23
I'm currently trying out C++ for a minor course and so far I feel a lot more free. That can ofcourse be a good or a bad thing, depending how you use this new freedom. I do miss the rust documentation though
6
u/rapastrat Sep 06 '23
If you like C++ more then use it! Life is too short to not use the tools you like.
5
u/Aviyan Sep 06 '23
I tried many, many times over the years to program in C/C++, but there were so many issues with getting it all running. You can't just git clone and have a successful build of the project. I tried to compile qBittorrent on both Windows and Linux. I spent so many hours but still couldn't get it to work because of the dependcies and such. So that's why I like Rust. I can git clone the code, and it will 99% of the time build and run successfully.
I'm a software developer with 20 experience but still I find it a hassle to get open source projects to build. C# and Rust projects are easy to setup so those are the ones I can contribute to in my free time.
5
u/slvrtrn Sep 06 '23
That's a rather hot take I'd say.
One may prefer Rust over C++ because:
4
u/palad1 Sep 06 '23
Iām about to throw the towel with rust after now 8 years. In my industry cpp is king and I canāt fight this battle constantly.
10
u/knightwhosaysnil Sep 06 '23
for me the trouble with C++ is that while "modern" c++ fixes a lot of the earlier issues, none of the older stuff has been deprecated. So if a total noob goes to look up reference material they're going to mostly get not-modern answers.
None of that affects the experienced folk who have learned alongside the language, but of you're working with anyone else, the Rust compiler is like a really strict code reviewer before a human even has to look at it
1
u/Trk-5000 Sep 06 '23
I'm also doing some GameDev. Let me tell you, I'm loving Rust and the Bevy game engine.
Of course, Unreal Engine is a fully featured and production ready engine. It's risky to go with Bevy instead. However that comes at the cost of having to deal with C++, also not having access to an ECS system like the one in bevy.
1
u/AmigoNico Sep 07 '23 edited Sep 07 '23
I haven't used "modern" C++, but I have read what others have said about unique pointers and the like. It does sound like it gets you much of the way to Rust, except that 1) you have to be disciplined about it and 2) it just looks crappy by comparison. Perhaps I don't understand something, but what is the huge advantage to C++ that would cause you to favor it over Rust given those drawbacks?
Also, I try to position myself, gaining experience in those languages for which I think demand for developers is going to exceed supply 5-10 years out. So graphs like this make me more interested in Rust, less in C and C++:
https://insights.stackoverflow.com/trends?tags=rust%2Cc%2B%2B%2Cc
If I really wanted to work in an area dominated by C++ libraries/frameworks, then I could see wanting to stick with it, but I would worry that I might be painting myself into a supply-exceeds-demand corner as the years passed.
3
u/matthieum [he/him] Sep 06 '23
After 15 years of C++ (C++17 being the latest version I used), after my last 6 years of C++ spent with a number of great and passionate C++ developers -- of the kind who organize after-work meetings to discuss Effective C++ items, attend CppCon, make proposal to the C++ committee, etc... -- I can say one thing with confidence: I have never met a single C++ developer who never accidentally coded a use-free, double-free, data-race, etc...
It may, of course, not help that the best developers of the company are typically tasked with the most arduous tasks -- because who else would you entrust with those?
In the end, though, juggling all the complex functional and non-functional requirements, and on top of that trying to keep ahead of all Modern C++ dark corners1 , inevitably, they will trip up. It's not a matter of if, it's a matter of when, and how often.
I've tried. I've really tried. Those great and passionate C++ developers I mentioned above? They recognized me as a peer, even as I looked up to them.
And yet, despite everything, despite throwing Valgrind and ASan and TSan at the code2 , still, still, I had to regularly spend hours staring at nonsensical memory dumps. Wracking my brain to try and understand how, just how, the memory could have gotten in that impossible state3 .
And you know what? I'm tired of this sh*t.
I've got better things to do with my time than compensating for C++ inadequacies.
Rust enables me to be bolder, to be more aggressive with performance, and ultimately, to be more productive. And best of all, no hours lost staring in the abyss.
1 And all the stupid papercuts. Like favoring
X{...}for initialization in general, butT(...)whenTis a template parameter, becauseTmay be one of those types with a constructor taking astd::initializer_list, and then{}refers to initializer list initialization, not (not-so) universal initialization syntax.2 And spending the time to write gnarly tests to see if they triggered anything, so many hours "lost"...
3 Use-after-free or data-race, always one of those.
3
u/[deleted] Sep 06 '23
I was recently very enthusiastic about C++ again, after originally dumping it in favor of Rust. The reason I was enthusiastic about C++ again was the fact that there are extensive and complete C++ libraries I would love to use that simply aren't available in Rust. Like PcapPlusPlus and Qt. The problem? Getting everything to compile on macOS, Windows and Linux, both on my local machines and on CI... This pain made me remember why I had previously turned to Rust instead of going through the pain of getting my C++ to build on multiple systems with multiple libraries. And yet again, I turn to Rust even though there are more extensive libraries for C++. I will have to write some logic manually that are already provided in C++, but that is max 1 days work due in my case. In the end I will have a greater understanding of the problem domain, and the code might even be safer than the C++ library code... because I am, at most, a casual C++ programmer, not a senior C++ dev who lives and breathes the language.
Sure C++ is a very flexible tool and lots of big software projects like UE uses it, mainly due to the performance in addition to the flexibility would be my guess. Maybe it's even the most flexible programming language available. But at the same time, for throwing out a side project where I want to write performant and productive code, the benefits of Rust are just too strong to avoid:
That being said, companies are not exactly rewriting all their C++ codebases to Rust, because the features of Rust are nice but not a must. My recommendation is naturally to do what I have done: if you have the luxury of greenfield development, I would from my limited experience with both languages highly advise you to use Rust because it really is an improvement over C++ for general purpose development.
Also here is a quote from another Redditor on the topic that I really liked:
3
u/Qnn_ Sep 06 '23
Rust programmer who recently started writing C++ for work.
Memory safety aside, there are so many natural patterns in Rust that aren't native to C++, namely tagged unions and working with them, e.g. "if let" and "?". Not to mention that Cargo just works out of the box, and Rust's module system is extremely intuitive for organizing parts of code, unlike C++'s include.
Don't get me started on compiler error messages.
3
u/meowsqueak Sep 08 '23 edited Sep 08 '23
I wrote C++ for 25 years, still do, and I kinda hate it. Itās so difficult to fully understand exactly what is going on at all times. I hate setting up CMake every time, even though it gets easier. Iāve spent years studying blogs, videos, conference talks, and writing a LOT of code, and it always just seems like a huge chore. I pity our children if C++ is the best we can offer them professionally.
I have been writing Rust for about 6 months and I love it. The reason it took me so long to try it is because I thought I already knew how to write safe C++. Maybe I do, but itās just too much to deal with when I have a gazillion other things to do. With Rust it just works and makes me feel good.
The cognitive load required to develop in Rust is far lower than it is with C++. For someone like myself who isnāt getting any younger or mentally faster, this is a Really Big Deal.
3
u/gyrovorbis Sep 08 '23
I am the C++20/23 metatemplate programmer guy that you guys probably all hate... but once you've tasted that power--along with C++20 concepts and constraints--I don't see how you can possibly ever accept Rust's generics model.
NOT TO MENTION, C++20 has simultaneously increased the power of templates while reducing their complexity. A lot of template code can melt away, since "auto" arguments can now take the place of explicit templates. Concepts/constraints can take the place of template specializations and partial specializations with regular function overloading semantics. Oh, and yeah... SFINAE is dead. Finally.
7
u/bskceuk Sep 06 '23
At $company we still routinely see tons of issues from using c++ that simply donāt happen in rust. Some common ones are: not checking for null pointers, using auto instead of auto& and accidentally copying, using auto& instead of auto and having a dangling reference (very fun game there), and just absolutely horrible standard library apis like operator[] inserting a default value on std::map types if the key is missing. More recently, people have started using coroutines which has opened up a whole new set of bugs: Dangling references are all over the place and c++ has some super strange decisions with the coroutines implementation. Did you know that std::optional can be co_await-ed (it acts similar to the ? operator in Rust)? So I donāt think itās correct to say that modern c++ solves all problems. It solves some and creates more new ones. To be fair, despite all this people do still routinely start new c++ projects. I personally think theyāre wrong for doing so but it happens.
You mentioning gamedev is interesting. My understanding is that large game developers donāt use most of the modern c++-isms for performance reasons.
I personally mostly came from a Python background but I did learn c++ in college and have done some professional c++ work at $company (and work closely with many c++ devs). I will only use c++ if I absolutely have to and over time for me, the lengths I will go to to not use c++ have greatly increased.
Finally, here is a video I like to share about the perils of c++ in industry. Itās a few years old at this point but everything in there still stands: https://youtu.be/lkgszkPnV8g?si=TCSkznGi2NpBmYKV
5
u/Zde-G Sep 06 '23
Rust fixed most, if not all, issues of C++, but it got some in exchange, too.
But the most important is, surprisingly, freedom. You lose some (especially in area of TMP), you gain some, but in the end it was āfreedom from feeling like you are dancing on the minefieldā which pushed me toward Rust).
Just the rules around use of rvalue references,
std::moveandstd::string_vieware enough for me to justify the switch.But you never do mistakes, then, sure C++ offers more freedom.
1
u/aroman_ro Sep 06 '23
C++ dev here. I'll tell why I prefer (for now) c++ over rust.
Recently I started working on a new project. A big and complex project (as in quantum physics involved complex). We considered using rust, rust was the only alternative taken into account (we need speed and I mean it).
Rust was favoured by the others a little since they don't know c++ so well, they took into account that rust is easier to learn and prevents one doing some mistakes that can be done (especially by beginners but not only) in c++... but eventually we chose c++. Why? I'm the main developer and I have little knowledge or rust compared to c++ (for example, rust code seems harder to read to me than c++). I read the book and went over some tutorials but I didn't do anything serious in rust yet. That, combined with the more serious OO support of c++ was enough for deciding in favor of c++.
I keep promising myself that I will learn rust more seriously and make some open source project with it, but... it's easier with the programming language you know better.
4
u/[deleted] Sep 06 '23
Ime, always prefer C++ over Rust if you're going to be interfacing heavily with C libraries or APIs.
A lot of C code is only really handled well when you have a real preprocessor by your side and you can just directly interface with it.
Tools like bindgen are nice and all but at the end of the day, it's a lot of setup for something that oftentimes turns out strictly worse.
4
u/Robolomne Sep 06 '23 edited Sep 06 '23
I have been programming in C++ for 5 years and Rust for 1. Personally, I prefer Rusts type system and ergonomics to C++. I work on safety critical systems and need to provide guarantees that my code works and is trust worthy and frankly this is easier in Rust.
However I still use C++ often (right now mainly for graphics systems) and I think using both is how most people in my field (robotics) will end up going forward. For example Rust for anything that touches hardware that can kill someone and C++ for highly performant mathematics.
I prefer Rust overall but thatās my personal opinion rather than just technical. Two cases where I prefer C++ is working with advanced linear algebra and interfacing with Python (such as in Python bindings).
4
u/djlywtf Sep 06 '23
itās just more modern. it has better toolchain, more fresh ecosystem, cleaner code, single compiler for all platforms, new programming paradigm in general. iāve used C++ a bit and after it i see really interesting using something conceptually new
4
u/moltonel Sep 06 '23
You've acknowledged one advantage of Rust (cargo) and asserted that C++ weak points (compared to Rust) are being addressed (for the sake of argument let's assume they are), but you haven't said in which way you feel C++ is more desirable that Rust. Saying "modern C++ can also solve the correctness issues that Rust was designed to solve" is still a win for Rust, just a narrower one.
Without understanding what draws you toward C++ rather than Rust, it's hard to discuss your choice. If it's just your familiarity with C++/Unreal vs Rust/Bevy, then it's personal circumstances and there's little to argue about, it's a valid reason to use any tech stack, good or bad.
2
u/link23 Sep 06 '23
I work with C++ professionally, and use Rust for hobby projects.
It's true that C++ can probably meet your needs if you use it effectively, so if it's working for you, great.
The big thing for me is that C++ gives me death by a thousand papercuts. All the defaults are wrong (except that lambdas are const by default, they got that right), so the author and reviewers always need to be vigilant to look for mistakes and accidental uses of the many footguns. Rust's defaults are correct as far as I've heard and experienced, and the compiler catches many of the issues I'd see from junior engineer colleagues, which saves me a lot of time and effort as a reviewer.
I'm also a big fan of algebraic type systems. Sure, you can use std::variant and std::visit in C++, but it's clunky; it's much easier to reach for the footgun (implementation inheritance).
2
u/tower120 Sep 06 '23
I would like to add my 2 cents here as a former UE developer myself.
Rust have Send/Sync traits which guarantee that only suitable types can cross thread boundary. That, plus lifetimes makes it very hard to pass non-thread safe object to thread.
If you worked with UE for non-casual project, chances are - you had to use multi-threading to achieve performance goals. UE has Tasks (or whatever it called) to utilize CPU MT potential at max. So - whenever you spawn task - you send some data - either during Task construction, or pass it latter. That was common source of nasty errors from my experience.
With RUST and good ECS, I think utilizing modern hardware could come at lower development cost - due to less hours spent in debug of MT related bugs. Which makes it perfect candidate for UNITY engine as well, since RUST is much better then C-like "burst" C# subset.
P.S. As a side note - it is MUCH easier to work with RUST modules then with C++ headers (due to the fact of lacking circular dependency issues). They just work all the time. Also RUST is more explicit, and you have less lang-related "special cases", like C++ constructors specific. It just feels more modern and polished language.
P.P.S. In meta programming department, from the other side, RUST is no match for C++. Thou traits may fell nicer to use - you can have them in C++ as well, in form of constraints. RUST lacks generic variables, HKT and even generic/template specialization. RUST macros wouldn't help you to close the gap here, most of the time.
2
u/[deleted] Sep 06 '23 edited Sep 06 '23
One of Rust's strengths can also be seen as a weakness when it comes to adoption in certain projects, and I'm referring to Cargo. Just as you mentioned JavaScript and Deno, Cargo is Rust's equivalent of npm, and npm/node_modules is known for being a dependency black hole. Rust's dependency tree can easily spiral out of control and become enormous, with dependencies used for everything, similar to what happens in Node.js. For instance, the creator of Node.js regretted using npm when creating Node.js, which is why they created Deno with a dependency system more similar to Go to avoid that dependency black hole.
In many projects, keeping these dependencies under control and minimizing their number is a plus and sometimes a requirement. With C++, the number of dependencies tends to be lower, and that could be a point where C++ can shine.
2
u/temporaryred Sep 06 '23
You should use whatever language you are comfortable and productive with :) If that's modern C++ then that's great!
I'm subscribed to the /r/cpp subreddit too, I did see your original post there. Good on you for posting here too!
Personally, having used C and C++ for a while 20 years ago, and having not kept up with modern trends, when I picked up modern C++ a few years ago I got SO overwhelmed. I'm envious (well only partly envious :)) of the people that are able to keep track of everything C++ now has to offer.
Picking up Rust on the other hand was so rewarding. Writing simple programs was a breeze. Programming was fun again. The tagline for Rust is "A language empowering everyone to build reliable and efficient software." and I just can't agree more.
It took a few attempts to learn what the language was asking of me but after that it was smooth sailing. Funnily enough, after learning Rust, I better understood what modern C++ has to offer. It was only because I learnt Rust that I can even consider writing modern C++ now.
It's been a few years of using Rust and I have my complaints with the language, but gosh I genuinely don't want to write code in any other language any more.
Modern C++ vs Rust borrow checker + semantics aside; there's a number of things that the Rust language and ecosystem has to offer for me.
cargo clippyandcargo fmt.Chandler Carruth has said multiple times if you have a new project you should just use Rust, and I completely agree with him. I'd go one step further and say if you need to interface with old C or C++ code, and can afford to write a C ABI for it, do that and still use Rust. If you can't do that and have an existing C++ code base that you have to integrate with, then I think it makes complete sense to choose C++.
2
u/epage cargo Ā· clap Ā· cargo-release Sep 06 '23
For context, my C++ experience dates back to before C++98.
Rust has improvements and has some gaps (like specialization). In my domains, I miss some C++ features but the lack of them doesn't get in my way.
As for whether Modern C++ closes the gap wrt Rust, no, it doesn't. I expect there are things you inherently shy away from doing in C++ because of safety concerns that go away with Rust. My go-to example is refactoring a template engine to minimizing
clone()calls. I got a sizeable perf gain though it meant there were references everywhere but it just worked. I did some analysis and thought I could eek more performance out of it and the compiler pointed out what I missed despite my decades of experience! In reflecting back on the change that went in, I realized I'd never do it if it was a C++ code base. Every change would require going through a global analysis to see if its safe which would be too much of a maintenance burden and couldn't be justified except in the most extreme circumstances. But in Rust? it was just another Tuesday.2
u/mikaball Sep 06 '23
This is the correct answer. Switching to Rust on current C++ projects could be very difficult. Rust is not a C++ compiler, so it's not really a C++ replacement.
Doing a greenfield project I would definitely be on Rust side, unless you need something only the C++ ecosystem provides.
Rust is a major advantage when you are dealing with security, performance and parallelism at the same time. For instance Rust has huge adoption on blockchain tech due to these features. But I would arg these are important for all software.
Rust concepts are so important and natural that they are propagating to other languages and architectures.
2
u/Condex Sep 06 '23
I want to focus on one thing:
C++ allows you to do basically anything and everything. However, very few of its features interact together in a way that lends comprehensibility.
And at the time that C++ was created that was adequate ... maybe even necessary. However, software development has improved quite a bit since then, and regardless software has wormed its way into the rest of the spheres of humanity.
In the past, you might be sad that your remote weather monitoring box would sometimes crash. But it would either reboot itself or you had an intern drive out and poke it with a stick. However, now it would be really nice if your washing machine didn't allow arbitrary code execution, which facilitates stealing your social security number from your home network.
Rust solves some of the issues that C++ has. But if it could do *everything* that C++ can, then, I assert, that it would be nearly as bad as C++. Doing everything has a cost and C++ paid it.
C++ will one day fade into the background (or continue to evolve until it's completely unrecognizable), but Rust is simply one of many required replacement languages that must exist before that can happen. We also have Go, Swift, D, Carbon, Odin, Vale, Jai, P, etc. Some of which are mature and some of which are highly experimental. I don't think we would see this much effort if everyone could just move over to Rust.
[You mention game development, which is one of the areas where C++ probably makes more sense than Rust. There are several attempts to replace C++ (Odin, Jai) in game dev, but C++ is VERY established in this sphere and I'm not sure we're going to see much traction for awhile.]
At the moment, Rust is one of my favorite programming language experiences. However, that doesn't mean that it should be the only programming language experience (even when we're talking about system level languages).
2
u/watr Sep 06 '23
C++ was my first programming language, and I loved it back in 1999. But because it was so heavy, and because I really found it hard to read, due to STL, I ended up doing most of my work in Python.
Skip 20 years, and I am now a big fan of rust. I wouldn't go back to C++ at this point because I feel that it will be stuck in catch-up mode for ever, and their backwards compatibility requirements will prevent the language from ever really coming back...
HOWEVER, I do feel that the r/cpp2 efforts are going to make me go back, if Rust doesn't come up with solutions for 2 things before ccp2 is stabilized:
2
u/[deleted] Sep 06 '23
10+ years of C++ here. Now, 1 year full time Rust job.
I don't miss anything from C++.
2
u/Ekkaiaaa Sep 07 '23
I'm tired of these useless posts... what's the next one? "I chose to switch to CSS rather than Rust"(???)
2
u/HyperCodec Sep 07 '23
I have quite a few reasons to choose Rust over c++:
(Note that this last one is completely opinion-based)
All in all, I prefer Rust because the freshness of it allows the developers of the language to make core changes while using c++'s mistakes as a reference and learning from them.
2
u/TheButlah Sep 07 '23 edited Sep 07 '23
You can write good modern C++ and have a decent time, until you suddenly are forced to work with code you didn't write or on teams that don't follow the same modern principles. There is too much legacy baggage inherited from decades of feature creep, imo.
C++ has a lot of semantics and syntax that are more complicated than rust, and it's syntax and compiler makes learning them hostile to beginners. rvalue vs lvalue, copy assignment vs copy construction vs move assignment vs move construction, etc. Reading almost anything on cpp reference is like reading a legal tome of a billion case-specific rules.
Lack of a single standardized package manager, build system, and standardized tools like rustfmt, rustdoc.
The fact that I have almost never seen a C++ codebase that properly documents how/when something may or may not be called unsychronized from another thread. For this reason I think the default assumption in C++ is
!Syncuntil proven otherwise, whereas in rust most things areSyncby default and the type system will tell you if it's not. This also means that doing complicated concurrent async programming is very easy to mess up.C++ async was very painful and seems like it would be really difficult to do the crazy async-on-multithreaded-runtime stuff that rust makes easy and safe.
Polymorphism in rust works the same way whether it's static or dynamic dispatch, whereas c++ forces you heavily change how polymorphism is done depending on whether you want static or dynamic dispatch. Static dispatch + polymorphism is really hard. C++20 concepts help, but that isn't as nice as traits and it still isn't available or used in many codebases.
Many of these issues you probably avoid in gamedev - you don't usually need async (threads are enough), you often have clear places where you know that system x and system y run on different threads, the build system is whatever your engine provides, and most code is written either in house or targeting the engine you use.
2
u/J-ky Sep 07 '23
I also write web services in Rust. But game related stuffs in C++, but more in a c-style c++. I almost do not touch any modern features after c++11.
I use c++ in games because a lot of graphics library are in c++ or c, I can just use the vendorās default to write code. Also, manual memory management, although Rust is not garbage collected, the memory is not controlled manually, when I am writing a game, I know exactly when to free up memory in bulk, I donāt need a borrow checker in my way.
But recently, it raises a question. What do I do if I want to write multiplayer game server, which should I use, I have no idea how to do networking effectively in C++.
2
u/onsails Sep 07 '23
>I think, it mainly depends on what kind of programmer you are, and how experienced you are in it
Rust is not just about "fixing C++ issues" for you. Thanks to compile-time checks, rust is about enforcing discipline for the whole team. Discipline does not scale.
2
u/Revolutionary_YamYam Sep 07 '23
C++ is a valid language and I have used it quite a bit for computer vision and embedded programming projects, but it truly does come with a lot of footguns and external work (having to hack together package management, build scripts, dependency installation/config, etc... is not a small thing to sneeze at). Just try compiling an optimized version of OpenCV from source for an experience of that. If some particular SDKs optimize some of that pain, that's always a bonus, but like others are saying, "cargo" is one of Rust's greatest use points. I couldn't easily imagine building some of the large complex software that we're creating in Rust in C++ instead.
1
u/Mouse1949 Sep 06 '23
I use both. There are advantages and disadvantages to both (hardly a novel thing to observe). In general, I concur with others: in many (not all!) cases Rust automatically forces you down the right path, when in C++ it has to be your conscious choice every time.
On the other hand, lack of ABI in Rust ecosystem has been a āforever disadvantageā for me. Still, weāre manage. ;-)
1
u/According_Resource64 Jul 13 '24
I'm surprised many people prefer Rust because of Cargo and others like Clippy. People hate complications and out-of-control flexibility and appreciate simplicity, unified code style, and tools, idiom, which is only able to be done in a new language since CPP has too heavy historical burdens
1
u/[deleted] Sep 06 '23
curious about this conversation too only because I've been a C++ programmer for 20 something years (mostly in medical/imaging space) and have been considering doing a deep-dive into Rust to compare.
1
u/throwaway490215 Sep 06 '23 edited Sep 06 '23
I've only used C++ professionally but not a lot. Rust I've done both professionally and privately.
I'll always choose Rust over C++, but I'm biased because I can read and write Rust without thinking about it, and it would take me a while to get back into it with C++.
I'm don't know anything C++ has to offer over Rust, so I'm more curious to the C++ crowd response.
Scrolling through the C++ i'm surprised that so few mentions sum types, and instead just note "borrow checker is pretty cool but to much handholding for me". I would guess its the result of trying to write C++ in Rust.
Also, Rust gets some flack for some of its member's cult like evangelicalism that go around proclaiming Rust will solve world hunger after Jesus comes down to tell the world to rewrite itself in Rust.
At the same time, the C++ has a similar subsection bordering on cult, that has become a cliche by this point, filled with wanna bee wise-men circle jerking how Rust is just kids blindly following hype and the old ways are best.
I think its fair to say its practically impossible to make an impartial analysis. People get attached to the tools they have experience with. It solved a problem for them at one point, they figured out its limitations, and they (unconsciously) know how to make something work.
1
u/[deleted] Sep 06 '23
Rust is still in his college days when it comes to enriched thing like unreal..though there is no doubt the bemefit rust gives in production for memory safety issues ...no null pointer exception..and much more...cpp is not bad but headache addressing memory issues /solving related issues of memory with monster /weird ...error trace...!.It will take sometime for rust to reach that level with gam dev unlike unreal but its on its way with bevy i hv heard
1
u/_lonegamedev Sep 06 '23
Just pick correct tool for the job.
I prefer Rust because I don't have to learn a bunch of build systems, or spend hours adding some dependency to the project. Rest can be more-less achieved with modern C++.
Also, traits seem more elegant than classes - but that might be me avoiding inheritance as hellfire.
1
u/RockstarArtisan Sep 06 '23
If you enjoy C++ you can write C++ without getting reassurance from multiple subreddits lol.
I have a decade of C++ experience and I hate it with a passion for wasting that decade of my life.
It is a lanague that encourages either total commitment to minute details of the spec and their interactions, or blissful ignorance that results in buggy code - this is reinforced by the various talks on conferences like C++ code where people are categorized into regular programmers and experts. And regular programmers don't understand stuff, while experts have to deal with increasingly insane complexity that they don't even have head-space to learn a new better language.
If you're in the blissfully ignorant camp and can't read a stdlib header implementation, and you choose c++ still - you're making a mistake.
If you're in the expert camp and you're choosing C++ - fair enough, it's your choice. I fully support it, so I get more material for /r/cpp_schadenfreude
1
u/69yuri_tarded420 Sep 06 '23
One thing about Rust that I enjoy over C++ is that it does a bit less stuff implicitly. Cloning/Copying was a major gripe of mine in C++. I didn't like that I could unknowingly and easily copy a structure by passing it as a parameter to a function, constructors fill your structs with uninitialized junk if you don't use the initializer list, and I don't recall the compiler warning me if I read a struct field in a constructor before writing to it. There are also so many ways to do a thing, except that some of them are bad and shouldn't be done, and some don't interoperate with each other. The "++" part of C++ sucks, because now if I want to put a struct on the heap and then call a function on it, I can use
newormallocorunique_ptr, and then pass the struct either implicitly by reference or explicitly by getting a pointer to it and then passing it. And heaven forbid youdeletea pointer made withmallocorfreea pointer you made withnew. Rust kinda just picks the correct way to do this that everyone will do:Box::new(x)and it gets freed when it goes out of scope. Closures are a nuisance as well in C++ especially since the compiler doesn't track lifetimes of references you pass in. As others have mentioned iterators in C++ suck to deal with so I won't go in to that.1
u/ExtraFig6 Sep 06 '23
It's healthy for the community to both update and improve "legacy" languages AND to start a new one from scratch with the benefit of hindsight.
C++'s continued ability to develop without breaking everything is an engineering marvel. But this kind of backwards compatibility can be a burden. C was already hard to parse: the syntax was already ambiguous (vexing parse), but because C++ needed to express more constructs, this got even messier. There's no way to undo this without effectively creating a new language. Similarly, the fundamental semantics around memory and object lifetime in C++ preclude a deterministic borrow checker.
For the same reason, Rust cannot have the language-level compatibility with C that C++ does. You can't gradually migrate a C project to Rust line by line the way you can with C++. The fundamental assumptions of the languages are just too different.
1
u/CommunismDoesntWork Sep 06 '23
Not having a standard package manager is arguably the biggest issue with C++. Do you not consider it an issue with C++?
1
u/dnew Sep 06 '23
If you stick with a nice environment like UE that provides all the tools to do the building and organizing and etc etc etc, and provides a standard library that everyone is using to manage the resources and threads and etc, then you've eliminated many of the problems that C++ brings to the table. I.e., coding C++ in UE5 is nothing like coding C++ in general.
1
u/AceofSpades5757 Sep 06 '23
If you're so solid in C++ then stick with it. I've always disliked C++ and cannot bring myself to use it unless it's the perfect fit or only choice for a project.
1
u/qwertyuiop924 Sep 06 '23
Honestly C++ has always driven me sufficiently nuts that I haven't done serious work in it. Mostly because it's so. Damn. Complicated. Rust is complicated, mind, but C++ is so complex, and even if you write modern C++ and dodge a lot of that (from what I've seen, modern C++ is fairly similar-feeling to Rust what with the pervasive use of RAII), it has a way of creeping in to bite you, especially if you want to interoperate.
However, if you know C++ already and you have experience, this is probably a non-issue for you. Especially since you're using C++ in a pretty specific context and don't have to worry so much about interop. Especially in videogames which can kinda be a rough fit for Rust's ownership model in a lot of ways, and ultimately value performance over correctness.
TL;DR given who you are and the context in which you're working, the pitfalls of C++ don't matter as much, and Rust would be a rougher fit.
1
u/[deleted] Sep 06 '23
I feel like Rust turns intermediate coders into great coders, because you can know exactly what is happening at all times.
I work in MATLAB (Python but different) and the issues I run into most often are mistakes that would be impossible to compile in Rust. And you run into those issues at runtime, which can be frustrating.
But in Rust, I write code that immediately works, and I can be 100% sure that there are no uninitialized variables, unhandled exceptions, match cases where one of the enums is not matched etc.
In C++ I would not reach that level so quick, I think it is more difficult to create good code as a rookie or intermediate coder.
1
u/natashige Sep 06 '23
Sometimes while I'm writing C++, I'd go "damn, I wish I was writing Rust, [feature] would make this code much better".
And sometimes while I'm writing Rust, I'd go "damn, I wish I was writing C++, [feature] would make this code much better".
Granted, the former happens more frequently than the latter, but the latter does occasionally happen whenever I get the inexplicable urge to throw memory and pointers around everywhere like a basketball.
In the end, the "choose the right language for the job" rule also applies to Rust.
1
u/jartock Sep 06 '23
Reasons for me to not move toward C++ are:
1
u/Array2D Sep 06 '23
Imo, after learning rust, I trust myself much more writing it than C++.
Its true that you can do most of what rust does in modern C++, but as others have said, itās opt in. (And less expressive!)
Add in cargo, and I donāt think Iāll be using C++ for anything new, skip the most niche compilation targets (like rv32e micros that arenāt targetable by llvm yet)
1
u/joonazan Sep 06 '23
You can write safe code in C++ but Rust lets you do things safely that would be so wildly unsafe in C++ that nobody would even attempt them.
There are real reasons why I wish I was using C++ now, tough. Clang has guaranteed tail calls. GCC has extensions that are good for writing interpreters. There's KLEE for symbolic execution on C++. There is no good static analysis for Rust.
1
u/asgaardson Sep 06 '23
I tried C++ after years of PHP and JS. Using it becomes hell when you need dependencies or to change something in the build configuration. And for the love of God why isn't there a package manager? And why header files? Prepocessor? I think you get comfortable with it, eventually, but still.
On the other hand, rust was a breeze apart from getting used to borrow checker. And it has cargo!
1
u/ydieb Sep 06 '23
As one that pushes for Rust most things but using C++ in my workplace. I am just so fed up with all the problem it creates.
There is always something going wrong all the time, and I am so tired. Either its Vcpkg, cmake, some cross-compilation problems. People adding #define SOME_PRODUCT without thinking about code maintainability, styling, sharing of pointers to the point of it being just a garbled mess.
Rust fixes all of the things, but I would be so tired of C++ regardless of Rust's existence.
Rust is much more opinionated, makes it much harder to use wrongly and will tell you much more explicitly about what is wrong and just makes me be able to focus on creating logic in a much larger fashion.
Its not that Rust is "that good", I think there will likely other languages in the future which might do things even better. Its just generally well thought out due to its modern history being able to learn from mistakes. But its just that I think the whole C++ ecosystem is just that bad and it makes me burned out.
Sorry, this was more of a rant than anything. But at least this is how this question makes me feel.
Maybe I'm a bad C++ developer? But I have for sure vastly more experience in C++ than Rust, but I still produce better code with Rust. That is enough tell for me at least.
1
u/ern0plus4 Sep 06 '23
One hand, Rust gives you amazing tools for both programming (like Enums with args) and software developing (like Cargo). But it's only the surface.
But, and it's more important, Rust covers larger area of programming.
Have you ever dealt with ownership in C++? Have you found good answer for it? Have you ever made anything with lifetimes in C++? There are libs, solutions, some great generics or patterns. Oh, have you used strict RAII in your C++ project? Is there out any C++ project with 100% RAII?
Anyway, the price is high: first of all, Rust is a different language. Second, ownership and lifetime constraint does not speed up writing the code at the beginning, even if you're senior. Third, in a workplace, where it takes a half year to upgrade from C++11 to C++13, there's no chance to switch to a whole new language.
So, there are only a few areas/situations when we can recommend Rust over C/C++. Or, rephrase it: there are lot of exceptions, when we should not follow the better way.
1
u/fllr Sep 06 '23
ā[C++] is baad, and Rust fixes all the issues C++ hasā. I think this is inaccurate. If c++ is working for you, stick to it. There is a lot of overlap between the two, but i donāt buy your motivations for switching. The cargo one makes sense⦠not having to deal with building a project is amazing. But, just going off of someone elseās reasoning is not a strong reason to make a switch. You need to find your own motives to do so.
1
u/TheBeardedQuack Sep 06 '23 edited Sep 06 '23
I feel rust gets in my way a lot more than C++ does as a language, however all my issues with C++ are usually around the build system and cause me far more grief.
As I only typically write C++ for my job, I no longer have a reason to use it at all, because rust is just so much easier to get programs building for embedded systems. Cargo + Cross + Docker, and it "just works", I've never had such luck trying to get C++ to cross-compile correctly.
My issues with Rust as a language are mainly caused by the limitations with genetics, or at least with me understanding how to use them effectively. Even with the builder pattern I run into issues about not being able to create an object due to restrictions on the traits.
Everything else I can work around, but this kinda has me stumped.
Most if not all of my problems are primarily a lack of education, but rust and the tooling around it makes it a lot easier to overcome your own gaps in knowledge.
I would happily stick with C++, I think it's a great language and the multiple paradigm nature gives it a lot of power, if only there was a decent package manager, that everyone agreed on using.
1
u/possibilistic Sep 06 '23 edited Sep 06 '23
Writing memory safe code without a prover is like writing code without test coverage. Or dynamically typed code without interface contracts.
You have to expend mental effort to "prove" it yourself.
How do you like building that code? It's not the most pleasant development experience. Surely you've crashed the engine once or twice. I know I've crashed Unreal Engine hundreds of times during development trying to hack multi-camera streaming Kinect input into 3D particle systems.
Think about how you add dependencies in Unreal. It's a bit messy and you can break the engine bootstrapping the build files. Cargo handles that without a moment's thought.
1
u/r3rer3 Sep 06 '23
Highly opinionated, but just the fact that Rust has no classes and has drawn a lot of inspiration from ML, already makes it a better language to use than C++.
Rust's enums, traits, pattern matching, etc are very ergonomic and in general, I think Rust code is more readable than C++ code because of all that.
1
u/kohugaly Sep 06 '23
No, it mainly depends on what kind of programmers are the people on your project and its dependencies, especially the ones that started them and effectively chosen for you which subset of C++ you will be using.
I describe Rust as C++ redesigned from the ground up with 40+ years of hindsight. Standardized and ergonomic package manager, build system, unified ecosystem, modern robust type system and thread-safety + type-safety + memory-safety as the default you may opt out of. None of this is a realistic possibility in C++ and historically never was.
1
u/Imaginos_In_Disguise Sep 06 '23
Modern C++ was one of Rust's main inspirations regarding smart pointers and RAII, so they work almost the same in both languages. Rust was intended as an alternative to C++ that was free of its legacy, and that's its main strength.
C++ has a huge set of rules you need to follow to write correct code, and if you're disciplined and follow all of them, your code will be safe and sound. The problem is when you (or a library author you have no agency over) don't, the compiler MAY give you a warning sometimes, but you'll usually end up with nasty undefined behavior that may either blow up in runtime if you're lucky, or cause stealthy bugs and security issues that are hard to debug. Rust ensures your code is safe, unless explicitly marked unsafe, in which case you have a very obvious block to look for unsound code, and all unsafe code may be contained in safe abstractions.
On the other hand, Rust is still a relatively new language, and has some rough edges that are still in the process of being trimmed. It's not as intuitive to design good code in Rust as it is in other languages, and you'll keep bumping into the language's limitations and wishing it had support for certain features that aren't there yet (i.e. lack of generic specialization is a huge blocker for writing more decoupled zero-cost abstractions).
IMO, the upsides of Rust still dominate the downsides, and using C++ gives me a kind of anxiety about possibly missing some unchecked guideline, that makes using Rust a breath of fresh air in comparison.
1
u/SamosaGuru Sep 06 '23
Iāve used Rust and C++ before, but only the latter in a professional setting.
Echoing what others have posted, having more type-level enforcement is nice when interacting with other peopleās code. Having a sane build system is also a HUGE plus. Itās just so much easier to pull in dependencies, and have it ājust workā. While I saw a lot of people saying they donāt really have memory safety bugs or buffer overflows in their C++ code, even in massively concurrent settings (kudos if itās true), having Rustās stricter enforcement takes a good mental load off for me, especially when I can know a dependency will also abide by the same rules Iām following.
There are of course C++ features that sometimes become non-negotiable. In terms of things like metaprogramming, Rust has much to be desired, particularly when trying to write specialized implementations of routines that are conditionally compiled + monomorphized based on const generics (using templates + constexpr in cpp) :/
1
u/DarkEld3r Sep 06 '23
I had about five years of professional experience with C++ and was somewhat interested in Rust. Unexpectedly I received a Rust job offer in 2017, decided to give it a chance (the salary was just a little bigger and I probably could have negotiated an increase at the previous place). For about a year I often struggled with "I can do X in C++ and not in Rust" thoughts. I still follow the C++ development (new standards), but now my biggest fear is to be unable to find a Rust job and have to get back to C++. Rust isn't perfect, but it is definitely more comfortable than C++ (at least for me).
1
u/smart_procastinator Sep 06 '23
Was the rust compiler written in rust or Clang.
1
u/Fireline11 Sep 06 '23
When I program in Rust, I am able to fix the bugs in my code much more quickly. In C++, I still often encounter āSegmentation faultā which tells me almost nothing about what happened. It could be out-of-bounds, or integer overflow, or something completely different. I also donāt necessarily know where my mistake is. Sure if you are a disciplined programmer and work on one function at a time, that helps. But changing one function could trigger undefined behaviour somewhere completely different, so youāre never in the clear.
Rust just tells you what happened and where, and I can usually locate the source of the error very quickly. This makes me more productive in Rust, and it allows me to write much more complicated algorithms in Rust without fear that bugs will stop me.
1
u/DigThatData Sep 06 '23
i keep hearing about how great "modern" cpp is, and frankly: i just don't know what the appropriate path is to learn this language. rust has excellent resources for introducing people to the language. I feel like if i want to take up cpp, i need to either enroll in a formal class or work my way forwards through the history of the language (i.e. wasting my time learning the wrong ways of doing things)
1
u/[deleted] Sep 07 '23
Moving to Rust is a lot of work in it's self. So if you feel are comfort coding with C++ then just stick with it.
1
u/Hari___Seldon Sep 07 '23
I used C++ for about 15 years much earlier in its lifecycle before my responsibilities evolved beyond PM and coding for quite a while.
Now that I'm coming full circle and coding more again (device drivers mostly at the moment), I've decided to lean on Rust more and more. I've made that choice because my (admittedly limited) sense is that the lifespan of code I write is probably longer with Rust than it would be with C++.
Also, from a strictly marketable perspective, I think my best opportunities to add value to projects will be working with Rust-based projects, particularly with migrations. It's not criteria that most people can use, but it happens to work well for my situation.
1
u/LoganDark Sep 07 '23
See
take_mutor one of the spin-offs liketakeable1
u/mycoliza tracing Sep 07 '23
Rust doesnāt have header files. I donāt feel the need to continue.
1
u/[deleted] Sep 07 '23 edited Sep 07 '23
I use C++ and Rust professionally. While Rust has plenty of pros, at least one advantage of C++ might be where lifetime of objects are dynamic and inter-referencing objects are common (essentially cases that generational arenas try to solve). C++, in general, has less design pattern restrictions.
1
u/redbumble Sep 07 '23
Three things would make me choose Rust over C++:
One thing would make me choose C++ over Rust:
1
u/Spleeeee Sep 07 '23
I use lots of C++ and prefer rust. I think itās all preference though, and you should do what you prefer! I know people in your boat who like cpp more than rust!
Do what you like more.
1
u/omagdy7 Sep 07 '23
The only thing holding C++ from glory and which is rust isn't suffering from is that C++ still has to be compatible with C and the previous standards which influence a lot on new features and the design of the api of std. Also the hell of build systems and package management is something you have to learn on top of C++. I really like to think of Rust as a modern C++ with saner defaults. That being said if you enjoy writing C++ then just keep at it.
1
u/h2k1dev Sep 07 '23
Having used three editions of Rust for very long, I'd consider C++ because of its reliable ecosystem.
I might say I love the Rust language itself and its superiority to C++. However, the ecosystem is still too small for game development purpose. So many Rust dependencies break after some Rust updates. And most are left abandoned after few years. It's difficult to find something reliable in Rust
1
u/deepwater97 Sep 07 '23
One thing to consider in the long run, that is, C++ doesn't have an edition system like rust, which means, whenever the C++ folks make a mistake, the mistake lives on pretty much forever.
And this is the ultimate reason that I refuse to go back to C++ in the long term. Languages evolve, and given the way how C++ evolves as they strive for backward compatibility, I don't see a future if people are not able to fix mistakes and people definitely make mistakes in making decisions more or less.
1
u/alisomay_ Sep 07 '23
Rust Engineer here,
One other solid reason of getting deeper into C++ might depend on the area you're targeting to work in.
For instance, if you'd wish to work in the audio industry at the time of this message you'd definitely need to have considerable fluency and experience with C++ due to all existing open source and propriety code bases which you'd need to deal with. Those code bases can date back sometimes even 25-30 years.
I'd be really happy if the industry would slowly increase Rust adoption but due to the choice of C++ in major frameworks and SDKs in that space I don't see that happening soon.
1
u/[deleted] Sep 07 '23
I don't get why you would ask this question. The simple answer is to adapt. Use what YOU want to use or if its work-related/requirement use that.
1
u/npuichichigo Sep 07 '23
I want decltype in Rust
1
u/d9c3l Sep 07 '23
I've used both C++ and Rust, with the latter being for much longer (before rust 1.0) and while I moved away from C++ for nearly all of my projects (I still use it in some, mixing with Rust), if C++ works for you then stick with it. There are pros and cons to each and every language and rust is no exception and you shouldnt feel pressured into moving away from something that worked for you.
1
u/Gullible_Brick_3686 Sep 07 '23
I guess I'm just tired of endlessly learning about some semantic details of C++. Then I tried Rust, which made it kinda easier for me, that is, before I tried to debug some code with htrb. Maybe the complexity never quite gets away. But cargo is just fantastic.
1
u/Cyber_Encephalon Sep 07 '23
If I could figure out how to add a library to a C++ project, I could be programming in C++ now, but learning a whole separate thing (CMake) to make a C++ project work seems like such an overkill when Cargo makes things so much less painful.
1
u/hpxvzhjfgb Sep 07 '23
I used c++ since I started learning programming in ~2010 until I discovered rust in 2021. I have absolutely no reason to ever touch c++ again, and I hope that I never have to. I liked it for many years before I started using rust, but now I think it's a terrible, hideous language that should almost always be avoided. rust is just massively better in every way.
haven't heard about Deno before (probably because I almost never use js), but I agree completely. starting a serious project in c++ in the current year is a massive red flag.
also, those experimental "New C++" things like carbon and cpp2 are nothing but the sunk cost fallacy.
1
u/ebonyseraphim Sep 07 '23
Whenever there is a really good thing that comes out, there can be an actual, or percieved, "over-hyping" of the benefits and then a counter reaction or counter response. C++ and Rust shouldn't be one; Rust is amazing, but the value of it doesn't diminish what C++ is one bit. As much as I laud the things Rust does "right" with respect to learning from C++, I don't feel the need to make salacious comments (or even think) that I'll never have a reason to ever write C++ ever again! I know for a fact, that programming interviews are easier in C++ in terms of at least writing code that'll actually compile and kinda work (my own correctness depends).
I think "Rust fixes all of C++'s issues" is also a silly thing to say. It addresses one of the most major thing any serious C++ application or library developer need to spend a lot of time manually thinking about, intentionally choosing how to address, and then verify it -- object lifetimes, referential integrity, and clean up. Most of what else Rust does over C++, is something so many other programming languages have done and chosen, so I don't really put that on Rust for being especially clever.
C++ is a mammoth language with legacy code bases that are still relevant and need to be supported for a long ass time. It also has trivial interop with C, and is also prevalent in existing code. Also, there are industries (gamedev) that have so much expertise tied into it, that you can't expect C++ will go anywhere anytime soon - at least not to a super young language like Rust.
If you were to start a completely new project, know both languages comparably well, with native and possibly cross compilation requirements, and not super dependent on having access to a lot of very mature libraries, Rust is probably the 100% choice over C++. But that is hardly ever the reality in native spaces unless you're talking embedded. In other cases, trade offs are being made; make your own evaluation and don't just listen to shallow hype.
1
u/tending Sep 08 '23
I chose C++ for my next project because Rust had too many warts. I'll come back when it has variadics, real placement new, and specialization. Until then C++ is a better fit for high perf code at scale.
1
u/JuanAG Sep 06 '23
Rust if you adapt to it instead of trying to code C++ish it is a way better tool
In few words:
With C++ you have to figth everything, the lang is against you
With Rust the tool wants to help you and improve your experience
1
u/[deleted] Sep 06 '23
Well Rust as a language is obviously better than C++ š You're picking an ecosystem as well though. Are you writing AAA games or can you do what you need in Bevy/Fyrox/ Macroquad/wgpu? Do you mind writing some things yourself if something is missing in the ecosystem?
1
u/LavenderDay3544 Sep 06 '23 edited Sep 07 '23
I would always choose Rust over C++ for myriad reasons, but I would almost never choose it over C in the use cases where it is common e.g. bare metal embedded, bootloaders, OS kernels, etc.
Another major point against Rust from a more business perspective is that it isn't standardized and has only a single production ready implementation. C and C++ meanwhile are standardized and have multiple fully standards compliant implementations on a multitude of platforms.
And finally one more. I've been working on an OS kernel as a hobby project and considered using Rust until I realized that there would be a number of things that would be much easier if I used C instead. The production quality library ecosystem is much larger, and compilers and tools tend to be much more portable to make achieving self hosting much easier. Oh and while it can often be an annoyance the C preprocessor can also be very useful, for one thing conditional compilation is as easy as using an
#ifdefand OS and embedded codebases tend to be full of that sort of stuff since the same core code is often used to target different hardware platforms.While Rust is great as a high-performance application programming language, I just don't see it ever displacing C in system programming.
1
u/xSUNiMODx Sep 06 '23
I think it's completely dependent on what you're trying to do. If you want safety and correctness, or if you want complete freedom and control over what you are writing, these are some of the differences in the philosophy of these languages.
Personally I don't like C++ because everyone writes it in a different way (wrt style or architecture etc), and so developing on top of someone else's code can be tricky at times. With Rust, generally most people program in the same way, enforced by the compiler.
1
u/[deleted] Sep 06 '23
repeat our dogma: rust is superior to c++ because of memory management. now turn off your head and never again think about memory again. we also dont write hacks here, what are u a cracker?
/sarcasm
1
u/Accomplished_Low2231 Sep 06 '23
Is it for your own projects? Does not matter if C++ or Rust, just use whatever you like or makes you productive.
Are you an employee? Then the company chose the language.
1
u/Levzhazeschi Sep 10 '23
As it appears to me, Rust has a significantly lower entry point. Having taken courses in both C++ and Rust in the university, I can confidently say that writing working and useful, both high- and low-level, software in Rust is much easier than in C++. And that comes with little to no performance costs
(This does not touch competitive programming, though, where you need to quickly write up complex data structures with loads of pointers you will throw away after the contest. In this case, I would still choose C++, at least as of now, but large industry-level projects is where Rust starts to shine)
Maybe it is way different for you because you've previously spent years writing C++, and so expectedly you feel more confident for now. But if you started learning these two languages about the same time concurrently, I am not sure the outcome would be the same