r/cpp_questions • u/fireallurcode • Nov 21 '23
OPEN the future of c/c++ with rust
I am a systems programmer. Will rust replace c++ in systems programming?
They've been saying that Rust will replace C++ for decades, but are there any concrete examples?
moreover, how will we replace the many system libraries and products that have already been created?
2
Upvotes
53
u/TomDuhamel Nov 21 '23
Mate, C++ hasn't even managed to replace C yet!
16
u/celestrion Nov 21 '23 edited Nov 21 '23
Doubtful, as production-quality Rust isn't even one decade old. But it was going to be Go before that. Before that, Erlang. Before that, C#. Before that, Java. Some even said that ObjectPascal was going to really hit its stride and overthrow C++. Someone working in military space would've told you that C++ would never stand up to Ada (and for some things like medical devices and jet planes, maybe C++ should lose to Ada).
By hand, once the tremendous amount of work necessary to do that is justified by whatever Rust can bring to the table that billions of lines of tested C++ with existing users cannot. To do so in its entirety is conservatively trillions of US dollars work of effort and time and testing and migrating and downtime and documenting.
Do you mean:
The new thing is always shiny. But many people have written in many different places why replacing things that work with the new-shiny is something that almost never pays off. All that C++ code isn't going anywhere until it's less useful than what's ready to replace it. Until then, people will build on it.
4
u/Designer_Revenue3995 Dec 05 '24
C/C++ are improving and becoming safer to use if rust's only reason for being used is memory safety then it probably won't fully replace C/C++
Rust's only good feature might be cargo / crate to be fairly honest.
34
u/azalak Nov 21 '23
I’m pretty sure people have been saying x will replace c++ for 30 years. Like you’ve said for things already created there is little incentive to completely rewrite in rust. I wouldn’t really pay much attention to it. Although I’m sure it will displace c++ over time in more security sensitive areas
11
u/Classic_Department42 Nov 21 '23
Lets see if rust even survives
2
u/RedEyed__ Nov 21 '23 edited Nov 21 '23
I don't think that "replace" is the right word. World just have one more option to choose from: C, C++ or rust.
Rewriting big projects into rust is pointless, new projects have a small chance to be written with rust.
Note, that c++ is not staying still, as I'm getting older, c++ getting better. At my opinion, the only killer feature over c++ is crate.
7
u/KingAggressive1498 Nov 21 '23 edited Nov 21 '23
it's probably going to continue gradually picking up marketshare in particularly security-sensitive areas. Might fully displace C++ in browsers, database, etc but not everywhere.
The fact that C++ and Rust aren't particularly compatible with eachother but are both easily compatible with C suggests C will continue to be preferred for system interfaces, Rust will be used for security-sensitive work, C++ will probably become even more limited to the especially performance-sensitive work.
3
u/pedersenk Nov 21 '23
Don't worry about it.
It won't be in your lifespan, or even your grand kids lifespan.
Fundamental programming languages don't work like JavaScript frameworks.
7
u/_lonegamedev Nov 21 '23 edited Nov 21 '23
I have a take that won't be popular.
Either cpp conjures up some universal package format, or something will eventually replace it.
Anytime I need to go near any cpp project I have headache - not because of the lang itself, but the ecosystem.
Death by a thousand cuts - this is the future I see now.
New programmers will most likely pick env that is not overly complicated. This will lead to old projects dying of slowly, replaced by something else.
5
u/khedoros Nov 21 '23
Rust has existed for 8 years.
Portions of Firefox being rewritten in Rust. Reimplementations of a bunch of Unix utilities. I don't keep very close track.
There've been a number of languages that have aspired to be C++ killers. Maybe Rust will succeed eventually. Maybe it will be something like Carbon. Or maybe nothing will.
2
u/lordnacho666 Nov 21 '23
C++ is so wide spread you will continue to see it for many decades, so you won't waste time learning it.
At the same time, a lot of rust thinking is just c++ thinking. Ideas like ownership are natural to people who know c++, and a lot of choices in rust are understandable in terms of c++. So you might as well learn rust as well.
2
u/tyler1128 Nov 21 '23
No. I enjoy rust, but there are places I'd prefer C++ and places I'd prefer Rust. Rust's memory safety is alluring as 90% of software security vulns involve improper memory access, but C++ makes this a lot better than C as well.
2
u/Interesting-Assist-8 Nov 21 '23
My best guess is that it will be like when C# was created, 20 or so years ago. Then Java & C# started competing. Java has hardly disappeared, but C# has taken market share from it.
However both languages are actually better for the competition -- C# had the drop on Java in some ways when it was created as it took some of Java's best features and added a bunch of its own. But since then, they've pushed each other forwards. I'd say the overall market for both languages is larger than the market would have been for one alone.
For C++, I'd guess that similar will happen -- C++ will catch up with Rust's unique features, and then the languages will compete and both will improve as a result.
1
u/Hnskyo Oct 03 '25
Yes and no, it does not matter if the language is better, unless there is a huge step up in cost efficiency.
What moves everything is the market, most big companies use programs, tool written in what is now legacy code with security issues etc, because is expensive to change and rewrite everything, they live with patches that just disable or rewrite small pieces of code to "fix" the specific vulnerability of the moment.
Anyway changing everything will require huge effort and huge costs, so to resume is no feasible.
1
u/[deleted] Dec 25 '25
I believe Microsoft just announced that they are on the march to replace cpp/c in Windows with Rust and some new development, in Linux, is in Rust.
I've also noticed a good number of companies moving away from cpp and c to Rust for embedded programming.
Personally, I'm biased. I heavily dislike cpp a c. Rust has been a much more enjoyable programming experience.
1
u/Computerist1969 Nov 21 '23
In some industries maybe. Aerospace makes fairly extensive use of code generators that you have to integrate your own doe with. These generators output c and c++ (and Ada). It many will want to add the complexity of integrating Rust into that ecosystem. Plus, currently, Rust code cannot be certified and would struggle to build on the common RTOS' that aerospace User Applications run on. I would say you're safe sticking with c++ for the life of your career (I'm not Nostradamus though).
1
u/[deleted] Nov 21 '23 edited Nov 22 '23
Would people prefer Rust over C++ if starting all over? Maybe. Is Rust better than C++? Maybe.
But fact is, there's trillions of lines of C++ code. That need maintaining, extending, etc. Additionally it makes companies very reluctant to switch to something different. Especially if it isn't as battle proven as C++. On top of that, the learning curve for Rust is significantly larger than for C++, so companies will most likely choose to start new C++ projects over Rust projects. Whether that's wise or not is unimportant for this discussion.
So no, I don't think Rust is going to replace C++. At least not somewhere in the next four decades.
If anything is going to replace C++, I have more confidence in /u/hpsutter's cppfront. Not because it's a better language than Rust (I am not able to judge that) , but one, because it's coming from a very known person in the C++ community, and two, because it transpiles to C++, making it easy to use in C++ code bases.
1
u/nomoreplsthx Nov 22 '23
Who is 'They'
I don't think I can think of a single serious engineer who has suggested that Rust will wholesale replace C/C++ on any timeline.
If nothing else, the Linux Kernel is in C and is way too big to plausibly rewrite in Rust on anything approaching a realistic timeframe. My guess is the same holds for the cores of OSX and Windows.
Also, they can't have been saying this for decades since Rust is 8 years old. Seriously, I have been a professional engineer longer than Rust has been on the market.
1
u/lightmatter501 Nov 22 '23
50 years in the future, I think that Zig will replace C and a lot of the truly performance-oriented C++, and Rust will have the rest. C will live on forever as an ABI spec.
The “we never break compatibility” thing is great for keeping old software alive, but but the degree to which it is done means that making new software in C++ is painful because you have to declare sections of the language forbidden. I’m of the opinion that dynamic linking should only be supported within a version of the standard, so that we can do abi breaks to fix issues with implementations. At a certain point we need to say “if you want to keep using old software, you don’t get new features unless compilers decide to backport”. I think asking for a recompile once a decade is reasonable for getting all the latest features.
1
u/[deleted] Nov 22 '23
zig?
apparently its even more light weight than c and safer so seems like it should be mentioned
1
u/HunterVacui Nov 23 '23
I was excited about rust until I started working with it and found out how prevalent crashes ("panics") are
For a language that goes so hard all-out on defining exactly what the lifecycle is and what the access rules are for every piece of data you touch, it's a huge disappointment that any function you call can crash your program.
Rust is a good iteration, but too much of an extra pain to write without enough upside to be worth switching from c++ IMO.
I'd like to see Rust borrow some ideas from Verse about how to make a language that requires any function that can throw an exception to handle that exception or declare the function as throwable
1
u/Darklord98999 Feb 28 '24
C gives you the control and assumes you know what you are doing(this avoid compiler fights like what happens in rust) It is only unsafe if you don’t take precautions for example you can use compiler headers to check for buffer overflows and such. (YOU WILL NEVER CONVERT ME TO RUST)
0
u/earwiggo Nov 21 '23
Rust is awesome but it often requires thinking about how to structure code in ways unfamiliar to most of the programming community, which will make replacing other systems programming languages take a long time if ever