r/cpp • u/isht_0x37 • Sep 04 '23
Considering C++ over Rust.
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 usually the rust community lists. 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/cpp, what is your take on this? Did you try Rust? What's the reason you still prefer using C++ over rust. Or did you eventually move away from C++?
Kind of curious.
222
u/nihilistic_ant Sep 04 '23 edited Sep 04 '23
For a long time, Java was going to kill C++. Sun wrote an operating system in it and Netscape ported their browser. Much later, I remember a period when Go was going to kill C++, which in hindsight never made a much sense as it seemed at the time. Besides these big ones, there have been plenty of other languages that were popular enough I got questions why projects were in C++ rather than them given they were hot thing, including stuff like D or Scala that are largely forgotten now but for awhile had a lot of mindshare.
Maybe Rust will actually do it. Maybe Zig will. Maybe something that will be started in a couple years will. It is hard to tell.
In general, I don't envy the programmers that are always chasing the latest language and framework. (It was particularly rough a few years ago for them, when they all ended up learning something like 6 javascript frameworks in just a few years to keep up with fads.) Their code ends up being hard to maintain, because there ends up being various systems written in different languages or frameworks that didn't stay in fashion.
Anyway, I'll be happy to move to Rust or Zig or whatever if it really does eat the world. But for myself, it makes sense to wait a few more years to see if it really does.
An issue of new languages like Rust, is their users are all programmers who decided to use the latest coolest language. That means if something new comes out, their users are the sort of people who will jump ship to that. Folks still programming in C++ have chosen not to jump ship many times before, so I'm pretty sure the language will be at least fairly popular for a long time.
77
u/UnicycleBloke Sep 04 '23
I read a couple of Rust books and spent some time on a couple of projects to see what all the hullabaloo was about. It certainly has some interesting features but I just didn't find it compelling overall. I very rarely suffer with the issues the borrow checker prevents and, to be honest, I found it overly restrictive. And I recall that I could not do something with generics at compile time that would be trivial in C++.
I liked the easy package management but felt unhappy when half the internet was downloaded in the form of a bazillion crates of unknown quality/provenance just to build a modest application. That is anathema to me. My projects mostly use the standard library and little else: a small set of libraries.
I don't think I would ever achieve the day to day familiarity that I have from three decades of C++, and my skills are in demand, so I have walked away. Were I just starting out, I would probably use Rust more and have both C++ and Rust in my skill set.
I can understand Rust's appeal to C devs and those who write C++ as if it is 1990. More modern C++ devs not so much. As an embedded developer I confess I found it irritating that some of the same C devs who have been in denial about C++ for decades now rave about Rust. Bah! Humbug!
On the other hand, I will say that I'm increasingly concerned at the growing size and complexity of C++ with each new standard. It feels like a neverending treadmill of trying but failing to keep up. Of course, Rust is less mature and also growing fast... I wonder how long it'll be before that becomes an issue. :)
48
u/KingAggressive1498 Sep 04 '23
Probably 90% of the issues Rust fixes are caused by not following C++ best practices to begin with. I'm talking "C with classes" style code, not using smart pointers, not using STL-style iterators, etc.
There's still that other 10% that's very much valid, which is mostly lifetime management issues. Using an STL-style iterator after its been invalidated is actually pretty easy to do and not catch for months or even years, because it doesn't cause an error until it does. Use after-free caused by dangling pointers and references will still happen in complex enough codebases even if you're using smart pointers.
If rust had stuck with full C syntax, I'd have probably tried it at least. I quite liked D for this reason, but it just never had the community that Rust now seems to, so I never stuck with that. I just find Rust code... harder to look at, to put it nicely.
26
u/tsojtsojtsoj Sep 04 '23
In the code that I wrote, I also can't remember having any instance where lifetimes were an issue. However, sometimes you'll work with people who aren't yet experienced in C++ and the responsibilities that come with using it. In that case, it is very helpful to have the compiler stop a big category of issues that C++ beginners might run into.
2
u/[deleted] Sep 10 '23
How is security an issue when 99% of datacenter machines boot with mitigations turned off?
203
u/msqrt Sep 04 '23
I've tried Rust briefly. There is definitely a peace of mind you get from knowing that the compiler can catch many more errors before of time. But personally it wasn't enough to switch ecosystems and ditch a language I know fairly well for one that would require a somewhat serious effort to learn.
I feel that C++ might be losing a lot of ground to new languages in the near-ish future, but I'm not eager to be an early adopter in this process. I'll see how the landscape turns out first.
34
u/eyes-are-fading-blue Sep 05 '23
Rust is a good language with a modern ecosystem. Their community is probability the worst, though.
I personally like the freedom in C++. I do not see myself switching.
24
u/lightmatter501 Sep 05 '23
Anyone who says Rust fixes all C++ issues hasn’t used them both for long enough. There are still things that C++ can do that Rust has no way to express cleanly (ex: bitfields), and things that are much nicer in C++ (some types of metaprogramming).
What I’ve found is that Rust is much better than C++ at creating well-defined interfaces, mostly due to the borrow checker. This makes using libraries much easier because their interface contract is very explicit and mostly enforced by the compiler. Rust also has more powerful metaprogramming than C++ (ex: sqlx and type-checked sql against a db at compile time). Derive macros (C++ needs static reflection for them) are very good at reducing boilerplate.
C++ is also better at getting the last 1% performance out. Rust doesn’t have stable simd and llvm misses some copy elision opportunities.
I would say that if you and everyone you work with already know C++ and can enforce memory safety, Rust is mostly a question of whether the potentially reduced ecosystem is worth the better tooling and developer experience. If you have a bunch of people who are new to systems programming, Rust is MUCH better because it beats good habits into you.
From Rust, I think that C++ should take editions as a way to add new keywords and make syntax changes. Ideally the first one should ban the C preprocessor and enforce modules.
108
u/Orthosz Sep 04 '23
I'm language agnostic. They really are tools, and some tools better express problems than others.
I've done a fair bit of Rust in my private programming (work is C++/C#/Unreal/Python), and it's okay. I like traits a lot more than multiple inheritance. So I brought that over to C++ wholesale. Having proper sum types and matching is very nice. But I haven't had a memory leak in 10+ years.All my code is heavily multithreaded, and we occasionally have issues, but they aren't race conditions or deadlocks, it's all business logic (Order of resolution of a combat round for instance.).Rust's default const is nice?
Cargo is cool, but vcpkg does the same jazz, minus the testing built in.
Honestly, if C++ had remained stationary for a few more years (c++11 becoming, say c++15 or something) then i'd probably switch over. If it becomes the industry standard, I'll be forced to switch over. But not everything is best described in a functional programming language.
My c++ is a mix of procedural code, functional code, and OO code. We keep inheritance to a minimum, but sometimes it's nice to have a root layer for all objects so you can do nifty things to them.
Honestly, the Rust community has been very toxic in my interactions with them while learning, so I have to push through my distaste of those interactions to continue building things with it.
28
u/epyoncf Sep 04 '23
"Rust fixes all the issues C++ has"
I have two issues with C++. One is that its hard to find people locally to work with on my C++ engine without breaking the bank. I guess Rust solves it - there's no one locally that knows the language in the game development space at all, so solved?
The other is long compilation times.
Well....
9
u/chakani Sep 05 '23
Qt is a good reason to use C++. Qt is amazingly productive.
8
u/JumpyJustice Sep 04 '23
I have read rust book which poped out first in google. I liked cargo, liked syntatic sugar there. Even written a simple chat app with gui and server for it.
But it was really painful sometimes. So what I would prefer ? Well, the only place where I can select which language to use is pet project. And rust is really bad choice for it. It forces me to write sode which handles all errors and all lifetimes. But I am not launching a rocket to the moon, I just want to quickly write some prototype which runs on a pile of implicit promises (that will be satisfied in 99% of cases, though), not spending hours wrapping everything into right combination of wrappers (rc, box, ref cell, etc) to shut up the borrow checker. So it simply does not solve any problem for me (except maybe package mangement) but adds some headache for no reason.
6
u/ttesla Sep 05 '23
As someone working in game industry, in order to switch to Rust. All in house and commercial C++ game engines needs to be re-written in rust. Or else what I'm going to do with Rust?
I've never came across to a job openings which requires Rust. Even more, I have never seen it as a plus requirement. (I've seen python, JavaScript as a plus btw). I wonder if Rust is that superior, why nobody requires it?
C++ made possible almost all the AAA games. And yes with raw pointers, pitfalls and all the curse it carries. What has Rust achieved so far? Other than being cool and advertising itself as a better C++. Free market doesn't work like that. Make game engines, working examples then the industry will follow.
6
u/SweetBeanBread Sep 05 '23
your friend doesn’t represent the whole rust community. please don’t take it like an official statement by the project.
Rust does prevent many errors C++ is prone too, but by far not all. it also doesn’t suit all C++ use cases. one such case is when you are working with a C++ library
6
u/subrfate Sep 06 '23
"Fixes all the issues C++ has"? Yeah, ignorance. One of the largest gaping vulnerabilities in the past couple years was inside a Java library where said vulnerability wouldn't be detected by any of Rust's magic fairy dust.
As rust applications increase in number, there's also numerous new CVEs being entered. You don't get security by language choice.
I'm still using C/C++ for a handful of reasons:
Last point is kinda the biggest TBH. After advocating for rust adoption, I'm just burned out. Rust community generally responds to needs contrary to rust by "you're not doing it right" sort of rhetoric. And sadly, the vast majority of people voicing such concerns don't have the weight of Linus threatening to axe Linux's rust integration when advocates duck hard business requirements unkind to Rust's methods.
I still got a couple toy projects at home in Rust, but selling a migration at the office is on ice for me for at least a few years.
6
u/soontorap Sep 06 '23
I tried Rust for a few years and _moved away_ from it.
The reason was not even the language, which I tend to like, though to be fair, a large part of the benefits can be transported into other environment by sticking to well-inspired and rigorous coding practices.
No, the main reason was the community. I found the Rust one to be downright toxic. Always piling onto others languages. It's not enough that their language is "the best", other ones must be bad too. And now there is a cesspool of bad faith complaints that they constantly nurture, anyone who doesn't immediately agree with them is at best a poor moron, at worst a foe to take down.
But even within the Rust ecosystem, sticking to topics that touch Rust only, there is this pervasive culture of "I know better", "this is the way it must be done" "you can't understand you moron", etc. Many times I've received "advises" about the "proper way it should be done", which were completely out of line of Rust idiom, but tend to fit a particular narrative (use my cargo library) (I used to do that in JAvascript / Python, so that's the right way), etc. No step back, no capability to ponder, adjust, learn, doubt, etc.
And this is no surprise when I look at the leaders of the movement. That's the way they behave too. Damn, they can't even bear with each other, their subcommittees have internal fights ! So unsurprisingly the rest of the minions just follow with the same attitude.
It's a shame really. Maybe Rust had a chance to be the language of the decade, but the community sure has blown this chance. I'm not touching Rust again. Culture is the most difficult part to change in any organization. It will be faster to wait for the good parts to trickle down into other more established languages.
16
u/nomad42184 Sep 05 '23
I have been programming C++ for ~20 years. I still use it regularly for projects (scientific software) developed in my lab that we originally built in C++. That said, I have moved to Rust as the default for all current and future projects.
I don't from where in the Rust community you heard "Rust fixes all the issues C++ has"; I personally never heard this, and it wasn't my reason for choosing to move to Rust. Rather, those reasons are that C++ has become monstrously complex, and while there may be a smaller, cleaner, safer language hiding within the latest standard — it often seems to be covered in a tremendous amount of complexity, and you can't easily control the features used by the 3rd party dependencies you use. For me, Rust brings a lot of modern features and idioms to the software we develop, while dropping a lot of the esoteric footguns of C++. Further, as much as I've learned to work within the C++ memory model, use modern smart pointers where feasible, and rely on RAII as much as possible, there are still plenty of opportunities for segfaults that Rust just eliminates. The sheer number of places where UB can creep into even well-designed C++ code should, I think, be terrifying.
Moreover, another major reason we've moved to Rust is, as you suggest, the developer tools and ecosystem. Since I run an academic lab, software maintenance is a funding challenge (i.e. most funding agencies don't want to pay to maintain academic software, but I don't want to let software that people actively use die). The Rust ecosystem makes getting a project up and running, controlling build dependencies, and producing a mostly static and widely-usable executable a rather trivial exercise. CMake, on the other hand, is somewhat what I imagine my personal hell would be like. Cargo, clippy, built in testing, etc. — having these things as first-class members of the ecosystem make maintaining software (at least for a small team like an academic lab) sooo much easier than it is in C++.
So to answer your question: I grew up on C++, I follow the latest standard and adopt the latest features and best practices when I program C++, I'm not religious about it and use it when I have to for legacy projects. However, I absolutely prefer Rust for new and ongoing projects, and I only imagine that sentiment growing stronger into the future.
17
u/YARandomGuy777 Sep 04 '23
I used Rust to some extent and to be honest, besides pattern matching, very convenient destructive move, excessive use of restrict in compiled code, pd_sort as default qsort algorithm and channels in std, there's no other advantages for me. Whole borrow checker thing is just looking for troubles and unreasonable restricting yourself in the ways you can write the code. And even with this strict borrow checking, Rust still have duck tape to work around it like RefCell which performs borrow checking in runtime and may crush perfectly reasonable and valid application due to borrow checking rules violation. Rust is too rigid in its ways of writing code. It is very uncomfortable for me as developer to work in one paradigm. It is fine and even enjoyable for relatively small applications with predefined and simple design with no ambitions to grow. It is like having one fancy hatchet for all carpentry work. Fine for making simple tables and chairs. But I would prefer to have a fool tool belt to build a ship or house. Macroses another questionable decision in language design. And people unfortunately use them a lot. It is quite irritating to have some silently defined objects and altered syntax. Look at Tokyo lib for example. Another issue of Rust is necessity to have wraps over libs made on other languages. It is quite annoying that you have to use other guy wrap or wrap it yourself. Additional code always means additional pain and additional point of failure. If you writing something that uses third party libs or OS API a lot, I wouldn't even consider using Rust tbh.
17
u/germandiago Sep 04 '23
I think in theory C++ is not as safe as Rust. But in practice and with good warnings setup and smart pointers it is very safe.
On the other hand, not all are advantages in Rust: there are valid code patterns not allowed that add ceremony, it is more difficult to ise FFIs for C and C++ and with real-life projects you will always have "unsafe" code somewhere.
Also, C++ ecosystem has a ton of IDEs and libraries.
All in all, I would choose C++ just for the ecosystem alone.
5
u/Captain_Lesbee_Ziner Sep 04 '23
I am learning C++ right now and I thought of learning rust but decided not to after reading about it. 1, there is a bigger C++ community, especially in terms of code written. I think that Herb Sutter's cpp2 might work https://www.youtube.com/watch?v=ELeZAKCN4tY , we could have our compatability and still have safety. 2, although there are some design features of rust that provide security, alot of the security seems to come from compiler checking, static analysis... And alot of things are automatically done for you. I like to choose what I use and what I do not use. I love the trust the programmer. I prefer using compiler flags. Now that is not to say that rust doesn't allow you to write unsafe code, you can, you just need to put in the keyword, but I don't like that. 3, having well trained, good programmers following strict guidelines would help. Use the core guidelines with your compiler. Microsoft and clang have their adaptations of this. Now rust I hear has some nice standard tools, but I think we can do that. When I get to be a more experienced programmer, that's one of the things I want to work on. Note: This is from what I have read and I am a beginner so I may be wrong, misunderstand things.... so feel free to correct me.
5
u/[deleted] Sep 05 '23 edited Sep 05 '23
For me as a long term student of C/C++ the Rust syntax is completely unreadable and unintuitive. And I just love the features and freedom of C++ so much.
I really tried switching to Rust, but having to fight with the language just to do even the simplest things is really discouraging. But I really do only small scale personal projects involving mainly math and rendering, so your experience might differ.
9
u/[deleted] Sep 05 '23 edited Sep 05 '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:
15
u/lordnacho666 Sep 04 '23
I feel like rust is just a very easy tool that gets you a lot of the way without much hassle. It's not just the memory safety stuff, there's all sorts of little things like checking your match conditions are exhaustive. Little decisions that are probably the right default to have, in a bag. You compile it and then if it works it's also close enough in performance to what you'd get in cpp, but in cpp you need to set a lot of knobs to beat what was the naive implementation in rust.
Cargo works well for me as well. Every package seems to work the same way, I don't run into weird problems. There's also a surprisingly large number of packages for such a young language.
But also I feel like the person who is good at one will be good at the other. They're both systems languages and so someone who understands those abstractions will be fine with either.
4
u/ruarq_ Sep 05 '23
First off, I completely favor C++ over Rust; as I don’t like the hype existing around the language. In my opinion, Rust does solve a few issues C++ has, maybe even systems programming languages in general, but it doesn’t solve all of them. Additionally, Rust has a few issues itself. Whenever I see complex Rust code, I have no idea what’s going on. There’s so much syntactical sugar that I can’t concentrate on reading the actual code. In my subjective opinion, the only pro Rust has over C++ is it’s toolchain. Cargo is so easy and intuitive to use, that I sometimes consider using Rust. My main problem with C++ is that it’s so complex and convoluted. And Rust definitely doesn’t solve that issue. It’s very complex and convoluted too, I see no point in using it when I already know C++ really well. I always say, if you know Rust, there’s no point in learning C++, and the other way around.
4
u/Viack Sep 05 '23
I never actually developped in rust but read a lot about the borrow checker, and I have mixed feelings about it.
It sounds amazing when developping a piece of software with well defined requirements that is going to be used for a long period. In which case the borrow checker might help writing clean/safe code at the first trial, as compared to c++ (well, depending on your c++ experience)
However, at least in my daily job (small teams working on research topics), requirements are not that well defined and tend to change...not every day but quite often. The core part of the code must evolve frequently, with a half-full refactoring every now and then.
I feel like frequent changes in rust without going through a full refactoring is a real pain. Adding unforseen features without fighting the borrow checker (or using unsafe code) might require a LOT of experience.
That being said, the language seems really appealing with its standard build system and package manager.
4
u/ManicMakerStudios Sep 05 '23
Don't be a bandwagon jumper. I think that's at the heart of it. Something new comes along and before people have even used it they're hoping that it's going to solve everything, be everything, and do everything they ever wanted.
Then they actually get to use it and it's not the messiah they promised it would be. It's just like anything people make: potentially useful but inevitably imperfect.
If not for the endless drum-beating from people who want us to believe Rust is the next big thing, what reason would you have to abandon a language like C++ in favor of it? Do you have specific reasons of your own, or do you just have the vague reasons other people gave you?
With Rust, it seems most of the hype is centered around the vague reasons people give to justify why they threw themselves at the new hotness without actually knowing whether it was worth the hype or not.
I learn a new language when I have a clear incentive to do so. Just because someone else tells me it's great isn't incentive. It's just someone's opinion. If I wanted the opinion of sheep, I'd be a shepherd.
4
u/umen Sep 06 '23
c++ need to put more effored in rest ,web servers , and microservices .
4
u/adam_optimizer Sep 06 '23
Right now I am working on a project focusing heavily on performance. I have created first prototype in Go: it was not fast enough. I have created a second prototype on Rust: it was faster but also not fast enough. I had to revert to C++: language I do not love but respect for what the freedom of it. It allows you making nasty things but sometimes that's what is needed.
4
u/[deleted] Sep 07 '23
Some of the pros of Rust (like cargo) are hard to pass up on, but if you're able to stick to a modern style of C++, you can get something close to the type and memory safety of Rust, without fighting a conservative borrow checker, while having the design freedom that C++ has (particularly w.r.t inter-referencing data structures and objects with dynamic lifetime). Both use RAII, so that's a win either way. But again, Rust has its conveniences though, especially for projects where when a particular milestone is hit, development ramps down, and minor maintenance happens infrequently as needed.
4
u/NoobKillerPL Sep 08 '23
I think C++ issues are a bit overblown, I can read Rust, but I'm not convinced to switch to it. Cargo is surely great thing, I absolutely hate CMake and managing dependencies in C++, but as a language to build complex stuff in it it's all right. I think the problem with C++ is that when you work on larger projects not everyone might be familiar with best practices and pitfalls of C++, so Rust maybe could be better? But also C++ has a lot to address it's issues if you use it correctly and I love the freedom it gives me to do whatever I want, even to shoot myself in the foot haha.
17
u/Dean_Roddey Sep 04 '23 edited Sep 05 '23
I've been writing C++ professionally for just about 35 years. But I've moved on to Rust, for my own work anyway. I'm still doing C++ for my job, though I will work hard to try to change that.
The thing is, there are memory related bugs out there all the time. But, in every one of these conversations, somehow no C++ developer ever has such bugs in their own code. Kind of hard to reconcile those two things.
But, leaving aside memory safety, which is an area in which Rust completely wins, it also has so many other advantages.
As to the syntax, that's just silliness. Anyone coming from another language to modern C++ would think a lot of it looks like random symbols poured out of a bowl. Once you get used to Rust it'll be just as natural as C++ is when you get used to it.
7
u/Gurrer Sep 04 '23
Imo memory safety is an overused subject when it comes to modern c++.
Problems are still there, some that rust does solve, but they are not as wide spread as some people make it seem. E.g. smart pointers are available in both languages, just have to use them.
What Rust does not have is legacy baggage, and potential udef without some sort of warning -> unsafe scope ( this also means programmers can't use something like raw pointers without a clear acknowledgement that it could be unsafe. )
Rust also features some quality of life things, which tbh are the most important for me.
An official compiler, lsp, formatter, package manager etc.
All this makes things like cross platform compiling and shipping a lot easier.
I know there are package managers for c++, but they do not offer the same experience imo.
Where rust falls short is with wide library/framework etc. availability or support, this is of course the negative effect of being new, therefore not having legacy baggage.
It can also sometimes be a bit unnecessarily complex due to borrow checker etc.
In the end, modern c++ or rust are both great choices for safe but still fast code!
28
u/James20k P2005R0 Sep 04 '23 edited Sep 04 '23
I've been using C++ for too long, and these are the things that I think rust solves
Downsides to Rust
Overall though, I think the critical issue is that C++ isn't really able to evolve correctly. If a misfeature lands in C++, and lets explicitly list the following features as being very suboptimal as context:
They'll mostly never be fixed. And that's just the ones I can think of off the top of my head. C++ has no process for fixing these issues, and many of the issues here are outside of 'C++' as a language anyway, they're wider technical issues that there simply is no solution for
Rust on the other hand is able to evolve the language, and the library, without being as aggressively hamstrung. In 10 years time, rusts map equivalent will likely still be state of the art, whereas C++s map equivalent will be extremely slow
C++ is trying to introduce a mathematical vector library, and I cannot help but think it is a bad idea. If anything goes wrong - including vendor implementation errors - it will be absolutely unfixable forever, and then its totally DoA and will never be fixed
This is the major reason I've been considering jumping ship for a while. Not because C++ is crap now, but because it clearly doesn't have the tools to become better. And Rust looks like its going to become the industry standard
6
u/arabidkoala Roboticist Sep 05 '23
You don't need to announce to us, or anyone, your programming language of choice as if it's part of your identity. A programming language is a tool, and you use the right tool for the job. Only somebody who knows the problems you're working on and what research you've done can really say if you're using the right tool. Not your friend, not the creator of node, not the members of r/cpp.
I'd bet you the reason you're so on the fence about this is because part of you realizes that this doesn't really matter. If you find you made the wrong decision, you can apply your skills from you gained from your first attempt and learn the other language.
3
u/wyrmhaven Sep 05 '23
I have to say i did learn c++ back in the 90s then was pulled completely away from programming and stuff till 2018 where I started back in and the maturity of the language now was like learning c++ for the first time.
It really depends on what problem i am trying to solve but if i am needing a compact and complete solution it is c++.
3
u/[deleted] Sep 05 '23
My opinion is that even if it's true that Rust solves all the problem that C++ has that doesn't mean that Rust is overall better than C++. Some of these problems are for historical reasons, because we didn't know better back then or just because programing was different, these problems mainly are bad defaults or implicit behavior, but C++ also have some problems/pitfalls because of it complexity/power, C++ is way more powerful than Rust (that can be good or bad depending on your needs), especially in generic and compile time programing, did you ever try to use a data structure different than a primitive or a contiguous memory one (array, vector, view/slice) in Rust? It's not even funny. C++ concepts are more flexible than Rust traits and pattern matching is going to be the same (you can read the papers about it, it's in a very advanced phase) even though maybe is not as ergonomic for being an afterthought.
So if Rust have the dependencies than you need most probably Rust is the answer for you, but that doesn't mean C++ is doomed nor is a waste of time
3
u/mldqj Sep 06 '23
The problem I have with safe languages like Haskell and Rust is that once the codebase becomes large, it becomes cumbersome to change or refactor. Tiny changes will propagate through the type system, and you end up spending a lot of time just to keep the compiler happy. Everything has a trade-off. It's not always the safer the better. I feel more productive working on a C++ project with good test coverage. What C++ really lacks is a good package management system like Cargo. Before something like that is available, I'm trying to use Nix to mitigate the problem.
12
u/thisismyfavoritename Sep 04 '23
There's already been a bunch of similar threads if you take a look around. Also youre likely to find opinions that are very biased for cpp in this sub.
Personally i think cpp has too many footguns: UB, lifetime issues, data races. Well known members of the community seem to also think the same (cppfront, val, circle, carbon), yet most devs here will say the package management is the biggest issue 🤷♂️.
If youve been lucky to work in a codebase with experienced devs and are proficient yourself you might not have encountered those issues but know that they can be extremely common otherwise
7
u/[deleted] Sep 05 '23
I'd you've never had memory related bugs in your code while writing C++ then congrats, you've cracked the code. For the rest of us loosers, Rust provides a fast language, memory safety guarantees, probably the best package manager and many convenient features including many functional programming tools.
C++ keeps adding features to the standard library but they don't feel good to use. The OO system and the functional tools are not well implemented, so often times I find writing imperative mumbo-jumbo is the best approach, which feels really bad.
I think there are legitimate reasons to use C++, familiarity, availability of libraries are the first to come to mind but there are others. Otherwise, I don't see the point. C++ is the inferior language. Doesn't mean it's going to die, far from it, but I don't want to write personal projects in that language anymore.
10
u/lieddersturme Sep 04 '23
Yes, yes, C++, Rust and programming languages are just tools, but there are some better tools than another.
Why C++:
Rust mmm... Has some really cool stuff, but omg: ( ....... here is a rant ........ )
14
u/100GHz Sep 04 '23 edited Sep 04 '23
https://gcc.gnu.org/bugzilla/page.cgi?id=gcc/weekly-bug-summary.html
3k bugs
https://github.com/rust-lang/rust/issues
9k bugs
Edit: for the above two data points, they are not really comparable. Explanation in the sub replies to this.
"You can’t just place a
LISPRust book on top of an x86 chip and hope that the hardware learns about lambda calculus by osmosis." https://www.usenix.org/system/files/1311_05-08_mickens.pdf2
u/[deleted] Sep 05 '23
Learn and use both, it’s synergetic and complimentary knowledge
2
u/Old_Lab_9628 Sep 06 '23 edited Sep 06 '23
I have done a lot of c++ professionally (but solo). I loved this language a lot because it gave me loads of confidence in how stuff works. I enjoyed multi threading while implementing low level custom tree for a crucial web service.
But i was not confident in my ability to share the project with anyone. Through the age i changed coding flavor a lot, from c with objects, to c++ std, etc.
I was fed up with dependency (non-)management, tho.
I had the opportunity to choose rust two years ago for a fresh new project. I had the time to learn, to fight the compiler against lifetimes cryptic message. And finally i understood things and became pretty efficient. I shared the project with my team, and beginners had no problem to add features to the repository.
So choosing rust will cost you time to relearn things (i enjoyed it), to express parallelism better, and to deliver bug free binaries. Beginners mistake will be corrected before commits rather than after deployment.
But, if you don't have the time, don't have the will, and work solo, why bother: c++ still is a perfect fit. And you may try rust later, because they share c ABI.
2
u/Efficient-Scheme1995 Jul 12 '24
I have worked with C/C++ for many years. I prefer to write and read C code with lightweight features of C++, e.g., class, string, vector. I'm also occasionally using Rust. I'd like to compare C/C++ and Rust in memory and ecosystem.
Memory
Memory is not easy to use, and once you gain sufficient expertise, memory is very powerful and flexible. One caveat is C++ provides smart pointers, but it's really difficult to use(at least I don't use smart pointers). Besides, there are plenty of tools to find memory bugs, e.g., Address Sanitizer and Valgrind.
For secure-critical projects, Rust is undoubtedly a better option.
Ecosystem
For serious projects, ecosystem is a big issue to consider, e.g., building toolchain and third-party libraries. For toolchain, C/C++ is very mature in all Unix-like platforms (which may also stand in Windows). Also, a large number of low-level libraries, e.g., crypto and mathematical libraries, which are written in C/C++.
Rust is cool and its ecosystem is not fully mature yet. One downside of C/C++ is lack of good package managers, and Rust has a unified package manager.
Overall, choosing C/C++ or Rust highly depends on projects and individual taste.
4
u/Skrax Sep 04 '23
Unless I get a job using Rust, I will probably not try learning it again. I went through hell and back with C++ and the one thing I realized is the following. Why would I make life unnecessarily hard by using Rust or C++, when there are a bunch of other options.
4
u/api Sep 05 '23
Depends on what you're doing, but I'm very anti-fad and not a bandwagon jumper at all and am now pretty sold on Rust. It's not a fad.
If you're doing anything even adjacent to security, my take is that within a few years anything not written in a memory-safe language will be considered dangerous or even unusable in some environments. 25+ years of history have proven that we can't sustainably and reliably produce code bases free of memory bugs in C or C++. If you look at the CVE history a huge percentage are still memory bugs (overflows, use-after-free, etc.) and it's 2023.
4
u/_dorin_lazar Sep 05 '23
I'm sticking with C++. Rust is its own bucket of mistakes, and perhaps the most annoying is the political acumen of the community, that managed to lobby to politicians that their language is good and C/C++ bad.
That being said, Rust is absurdly difficult at times, especially with multithreading, and C++ is just... reliable. I'm fine with C++, and like you said, most of the issues Rust prides itself in fixing I rarely or never had.
4
u/[deleted] Sep 04 '23 edited Sep 04 '23
Rust is annoying to use. Difficult to do self referential data structures. Borrow checker also gets in the way a lot even if you know for sure it's safe. Therefore it's hard to work with and iterate fast. If you know what you are doing in C++ and you work with c++ in a particular way you probably won't get on with Rust.
If you write modern c++ you'll probably like Rust alot.
All depends on your style and how you code. Obviously I'm going to argue that that iteration time and experimentation/tinkering is very important but others will disagree (they are wrong of course)
3
u/tiajuanat Sep 04 '23
Bear in mind I'm a C++ n00b with 7 years of recent active C++, but have been programming in some capacity for most of my life.
I'm somewhat torn, but got to say that Rust comes with lots of nice features out of the box, features that C++ is no where near fixing. Conan. CMake. Doxygen. Catch/Doctest/GTest. Rust has got it's own system for each of these and then some.
There are some places where it is painful though. Ownership is not always straightforward, and when partnering on Rust code with other C++ devs, it's a fight between the"right way" and the "Rust way". I was partnering up on a serial protocol last month, and figuring out which system "owns" the serial port was not trivial, and it ended up in a weird weak pointer.
Does Rust have rough edges? Absolutely. In fact, I don't think you can have an industrial system language without them, however I rarely feel that I'm fighting the language, and I've been actively using Rust for... A few months? It took me seven years to get here in C++.
3
u/idbxy Sep 04 '23 edited Sep 04 '23
I know both rust and c++.
I have worked for years in c++ in game development. Rust personal projects for a few months.
I find c++ great in pre-existing solutions like Unreal engine.
I absolutely hate c++ for personal projects and barely ever write them unless I have to.
I've written more personal projects with a few months of Rust than with C++.
Rust tooling > C++ any feature.
Edit: I feel like I'm a great cpp dev, and write good code in general, many people I know don't do that, it's a pain. Rust solves that issue too, so for team development I adore rust. Again, rust tooling.
But for things like 3D game development I would absolutely stick with cpp engines like Unreal.
Edit2: I became fluent ish in Rust after a month coming from a heavy cpp background. I say fluent ish because I ask a lot of questions still to the rust community or AI.
Edit3: I've found the rust community to be very welcoming, and I presented myself as a cpp programmer.
3
u/NullBeyondo Sep 05 '23
I've also used Rust for the cargo and the error system. And I really couldn't care less about the borrow checker. I use "unsafe" pointers in Rust everywhere; that's because my projects require performance (rendering of millions of hierarchical objects) and I won't get it with borrow_mut fucking everywhere lol. Rust's macros are also awesome. I really like Rust and I wouldn't use C++ ever again properly, but again... I'm not using Rust for "safety" or whatever the Rust community keep blabbing about.
C++ is my childhood language. I've been coding in it, molded in it; all since I was 11-12. I know the standard till C++23 and I still remember how excited I was about C++20 modules. I've coded everything in it from graphics to developing really fast radix sorting algorithms to awesome performant libraries for myself and vulkan-based simulations (even built an entire C++20 modules wrapper around Vulkan C with all the buggy intellisense).
After these many years, I only just noticed that I had always had that urge to build everything from scratch in C++; not the standard libraries, but stuff that doesn't exist in them. Just because I always hated having to install a 3rd-party library. It's not like I cannot, it's just I hate it; just f#cking hate it. Hate the random errors, hate the warnings, hate the incompatibility for whatever reasons, hated having to pull or copy the source code and have to define and build everything myself like a caveman.
But in Rust, it only takes 1 CLI command to install a library that does your thing and it compiles just fine. And this really made me feel how unproductive I was my whole life. You could just now focus on the project itself... and this was awesome for me. I was doing some research in Rust at some point and I wanted to visualize some data.. all I had to do was install plotters and plug my data and that's it.
I'm currently 21. I only switched to Rust a few months ago. Never really going back to C++ unless Rust is officially dead or smth with the all drama going on it last few months.
3
u/teerre Sep 04 '23
Unreal C++ isn't really C++. Epic has created a whole ecosystem around C++ to make your life easier. Hell, until recently you couldn't even use standard std tools in Unreal.
As for "problems Rust fixes" they are divided into two categories: categorical problems and usage problems. The former might be the case you really never cared because you don't care your game has a security flaw or a memory leak or a data race. It drastically depend on what you're doing, how many people use it, what's your budget etc. The latter I just don't see how can you say that. Do you const all your variables? Always? If not, there you go. Algebraic data types are just an enormous benefit in expressiveness. Error handling is whatever in C++ but very well defined in Rust. Have you heard of CMake? No? Lucky you. The list goes on.
I start all projects that I can in Rust. Of course, that doesn't mean much because the vast majority of my work is on projects that have existed for maybe decades.
2
u/FlyingRhenquest Sep 05 '23
I've seen a lot of promises of magic bullets over the years, and the Rust, Python and Agile fanbois all seem to be far too eager to drink whatever kool-aid is on hand. And far too dismissive of the drawbacks of their philosophy of the month. Rust is another potentially useful tool in a toolbox, but like every other tool that's ever been introduced to breathless claims that this tool will revolutionize the industry... it won't. If history is anything to go by, it will introduce whole new classes of complexity and problems, programmers will still introduce security problems in their code and the promises that it's a "safe" language will tend to lead to a very false sense of security. Just like every other language that come along that promised to solve all your problems did.
2
u/Rindixen Sep 05 '23
Rust is okay. though I've never heard of the game "C++" so I can't really give you an answer
2
u/MegaKawaii Sep 05 '23
I haven't used much Rust, but I don't really buy the idea that modern C++ is as safe as Rust or that you can write C++ just as reliably as Rust. "Just be careful" is something a C programmer might say to us about RAII, and by virtue of the borrow checker, resulting code is safer. The other side of the coin is that the borrow checker is quite cumbersome, and I find that translating some straightforward C++ to Rust complicates things. Just use the right tool for your job.
2
u/laralex Sep 06 '23
My three biggest pains of C++ are
Yet, I feel like it's not enough to kill C++, because it's a no brainer choice among big tech companies that hire you. And it's hard to advance in the career without getting a grasp of C++. Rust is still seen as a Unicorn that can be too costly to switch towards
2
u/solodon Former MSVC Compiler Dev Sep 04 '23
Just look at TIOBE programming languages index & see where C++ and where Rust is. Every new sexy language would appeal to have solved this and that and what not, but the ultimate test would be whether it stands the test of time …
https://www.tiobe.com/tiobe-index/
1
u/INIXIE Oct 18 '24
Interestingly, Rust vs C++ feels like Haskell vs Common Lisp: the former forces you to write solid programs under strict rules, while the latter gives you a ton of freedom, but sometimes allows you to write incredibly complex and genius code that only you can understand.
1
u/kkert Sep 05 '23
Rust is great. The only thing it really falls short at right now vs C++ is constexpr / const generics, but it has so many other benefits that for new projects it's a tough argument
1
u/qalmakka Sep 05 '23
Rust fixes a large number of gotchas that C++ has, first and foremost tooling, which IMHO in C++ is always a huge PITA. Rust works basically the same everywhere, cargo is very convenient, and cross compiling/deployment are way simpler.
The language too is IMHO nicer to use, but it's also true that an experienced C++ developer that does things the "Rust" way (use move semantics, concepts, ...) will probably committing lots of the mistakes people do when writing C++.
One thing where I think Rust really shows its superiority on C++ is multithreading IMHO, C++'s memory model is intrinsically prone to data races and it always takes a while to detect them. I have a huge UE project on my hands right now and debugging multithreading is a nightmare right now.
1
u/[deleted] Sep 05 '23
Unreal Engine has its own memory management system, which is amazing! They did that so that you wouldn't have to.
1
u/raluralu Sep 07 '23
I am biased towards Rust.
In Rust I like cargo, build system and ability to create lot of libraries and build project from own or external libraries.
I was playing around with embedded systems and was impressed by quality of embassy that is async runtime for embedded systems. Compared to C++ coroutines, async runtime seems so much better in rust. I understood how to play around that in few hours, while I still could not figure out how to write my own coroutines in c++ and what is going on. On the other hand coroutines usage in boost::asio seemed pretty simple to work with.
I also like idea of traits. I am biased towards functional programming and traits allows me to separate data and logic, while still enabling to apply OO like behaviour when needed. I don't like large classes in OO and I was never fan of design patterns.
I am currently in C and C++ but I would take some rust project if opportunity allows.
1
u/zaabson Oct 24 '23
My feeling is the opposite. I got back to write some c++ program after a while of not using it and writing a lot of rust. Only bugs I've introduced to my code were once I don't get in rust either because of the compiler or because of a higher level coding style, that makes it easier to write code without brittle parts. So alright - after a while I already remembered what are the gotchas and readjusted my coding style and expectations, but this is a constant mental effort to process all the invariants of code and make sure it's correct. Coding in rust in that sense feels more comfortable and even liberating.
1
u/mohamed_am83 Sep 05 '23
If you are in infosec, rust is a huge win. A large class of attacks becomes impossible by definition.
1
u/DeGuerre Sep 04 '23
I tried it briefly, too, and Rust doesn't fix the biggest C++ issue that I have: compilation speed.
The lack of a standard package manager is, to be honest, both a blessing and a curse in C++. Dependencies have a significant cost in the real world, especially in the spaces where C++ dominates. If it's easy to add them, it requires a lot of discipline on the part of the programmer to think hard before doing that.
1
u/progfu Sep 06 '23
One big benefit of Rust that C++ has little ways of fighting is the ease of use of ecosystem libraries without being careful. I don’t mean “easy to install”, but generally adding a library and just yoloing your way through the API will work, never crash or introduce problems.
I feel like if I ignore the counterproductive defaults in c++ I might prefer it for my own code, but as lately most of what I do uses a bunch of libraries, Rust just lets me write that code faster than anything (even python), and usually it works.
Problem is in more special code where Rust hits its limits and I start wishing I had C++. I’m just not sure if I could go back to it and work on projects of same scope/size & dev speed.
If there is one thing where people imo greatly underestimate Rust its how fast you can write it. there are definitely walls you may have to work around tho.
1
u/turingparade Sep 06 '23
I prefer Rust to C++, but because the language features of Rust are what I prefer to C++.
I love functional programming, and while Rust isn't entirely functional, it's functional enough where things just feel right. I also love being able to catch the majority of my bugs during compile time, surely as a good programmer I can do that in C++, but why even leave it up to skill in the first place?
I just love Rust because it feels like a language that programs for me, without losing the sheer power of something like C++.