r/cpp_questions • • 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

56 comments sorted by

53

u/TomDuhamel Nov 21 '23

Mate, C++ hasn't even managed to replace C yet!

13

u/fireallurcode Nov 21 '23

oh that is true

thx

16

u/celestrion Nov 21 '23 edited Nov 21 '23

They've been saying that Rust will replace C++ for decades

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).

how will we replace the many system libraries and products that have already been created?

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.

Will rust replace c++ in systems programming?

Do you mean:

  1. That industries will make a concerted effort to reduce their former code to specifications and feature points so that all the development work can be duplicated in Rust? This seems highly unlikely.

  2. That code will be written in Rust that would've been written in C++ had Rust not existed? This is already happening.

  3. That Rust will become more popular for new development than C++ is? Maybe. Oxide are betting the farm on it.

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.

1

u/fireallurcode Nov 21 '23

thx very

for ur opinion

2

u/sephirothbahamut Nov 21 '23

Curious, what makes Ada better suited to the fields you mentioned?

9

u/celestrion Nov 21 '23

Ada was designed for cases where correctness is preferable to development speed to a degree that is only viable in cases where a defect in code can cause extensive property damage, injury, or death. It is a paranoid programming language by default, and can have that cranked up in a way that mirrors MISRA in C and C++.

Ada has design-by-contract: you can declare preconditions and postconditions for function calls. Rust's borrow-checker is a very specific sort of statically-testable contract and is the most-cited reason that Rust is a superior systems programming language. With Ada (and other design-by-contract systems), you can have this for other user-defined types and any function or procedure parameter you want.

Ada has explicit concurrency, which C++ got in C++11 and later mostly as library features. In Ada, though, this is compiler-deep, so the static analyzer can help find potential deadlocks and races.

Ada has (from Pascal) an almost-unwieldy verbosity. Most if it is justifiable: explicit begin/end clauses gets rid of the potential for bugs like this:

if (condition)
   thing1();
   thing2();
thing3();

Some of it is to help subject-matter experts review code even if they're not great programmers. Ada.Text_IO.Put is easier for nonprogrammers to understand than std::cout <<.

As nice as these things are, it's tedious to write in Ada, and Ada doesn't have the best C ABI compatibility story.

4

u/TheThiefMaster Nov 21 '23

Funnily enough C++ has been working on adding function contracts. They're looking like they might be in the language "soon".

2

u/Classic_Department42 Nov 21 '23

Also dont forget SPARK, allowing to proof something something (on a subset of ada though)

1

u/EpochVanquisher Nov 21 '23

“It’s better than std::cout <<” is a low bar. That’s probably the most poorly-designed part of C++. It’s type-safe, but otherwise it just plain sucks.

2

u/Worth-Afternoon5438 Nov 21 '23

See :

https://en.wikipedia.org/wiki/Therac-25

https://www.youtube.com/watch?v=Ap0orGCiou8

for what may happen when a dangerous device is programmed.

1

u/bert8128 Nov 21 '23

What programming language did the therac use?

1

u/rachit7645 Nov 21 '23

Probably assembly

1

u/mredding Nov 21 '23

Not just probably - it was written in PDP 11 assembly by one guy, porting his prior THERAC-6 work.

Additionally, the code was never inspected, never certified, and the hardware and software were never tested together.

1

u/rachit7645 Nov 21 '23

Yeah it was a fucking mess

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.

1

u/fireallurcode Dec 06 '24

yes, i think so , but thease days , in many news and site saying that rust will replace with all c++ product!

like creator of c++ said, rust couldn't replace c++

thx for answer

have a nice day

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

1

u/Humble-Grand-4411 Sep 08 '24

Isn't there a huge initiative to replace C++ entirely in the critical infrastructure by memory-safe languages like Rust in order to prevent costly collapses that happened for instance couple weeks ago ...the blue deaths on airports etc.?

1

u/azalak Sep 08 '24

Yeah however I don’t think this will happen anytime soon to be honest. There are some code bases with millions of LOC that are decades old and the economic cost to rewrite it all in rust is something a lot of companies won’t want to pay. Eventually I’m sure rust will take over but there will still be areas where c++ remains dominant much like how COBOL is still the standard for banking despite being over 60 years old now.

1

u/Humble-Grand-4411 Sep 08 '24

Thanks for your answer, I am learning C++ upcoming school year nevertheless I was wondering about its pontential and it won't be probably replaced in sensorics anytime soon

1

u/azalak Sep 08 '24

I would just learn both, employers want you to know like 10 different languages these days anyway

1

u/rileyrgham Nov 04 '24

Systems will still crash with rust. It's not magic.

1

u/Jorfy69 Nov 21 '23

Bro I just learned both there both fun to write in just different styles

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.

1

u/fireallurcode Nov 21 '23

thx ur opinion

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.

1

u/tyler1128 Nov 21 '23

C is basically the minimal interface a language needs to implement to call functions in a library. It's why it's so common. Other languages can do more detailed binaries, but then it becomes much more language specific. .dll s and .so s both only export a name with a pointer to the function in the binary.

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.

3

u/[deleted] Nov 21 '23

Agree with this, I think the worst part of c++ is you need to learn how different package managers interact with different build systems.

Sometimes you can spend days making a combination of packages compile specially if you are new to the language.

You spend less time learning about how the language works (a giganting language at that btw) and have to worry about a bunch of things that are seamlessly handled by other languages.

5

u/khedoros Nov 21 '23

They've been saying that Rust will replace C++ for decades

Rust has existed for 8 years.

but are there any concrete examples?

Portions of Firefox being rewritten in Rust. Reimplementations of a bunch of Unix utilities. I don't keep very close track.

Will rust replace c++ in systems programming?

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.

4

u/AKostur Nov 21 '23

Reimplementations of a bunch of Unix utilities.

Nit: most Unix utilities are written in C.

3

u/khedoros Nov 21 '23

Nit: OP's post topic is "the future of c/c++ with rust" (complaints about "c/c++" aside, it seems like they intended to ask about both languages)

2

u/TheThiefMaster Nov 21 '23

The fact that Linux never supported C++ for systems development but is supporting Rust lends much greater weight to Rust being a "C/C++ killer" than any other language has had.

6

u/not_some_username Nov 21 '23

That’s because Linus hate C++ programmers btw

2

u/ManicMakerStudios Nov 21 '23

The biggest influencer on whether or not a language is going to kill another language is uptake. Period. If you can't get people to use your language, it can't overtake any other language.

And when your entire codebase is C++, you're not going to soak the cost of converting it to Rust "just because".

There's no such thing as a C++ killer. Not in our lifetimes.

1

u/TheThiefMaster Nov 21 '23

Languages very rarely die entirely - it's more where new development happens that matters. Just because some bank still runs COBOL doesn't mean it's not otherwise a dead language.

If Rust adoption continues to increase then C/C++ will fall and may end up with the same "old language" status as Delphi / Pascal...

2

u/ManicMakerStudios Nov 21 '23

The point is that fretting over languages "dying" is pretty pointless. It's just needless hand-wringing. If the language you're using becomes sufficiently unpopular that you're having a hard time earning a living with it, make the change. But, "Do I change now just in case?" Pointless.

Someone is better off long-term learning a foundational language like C or C++ because they can then migrate pretty much anywhere down the line. There's really no point worrying about what's going to happen 5 years from now when you can learn a new language in a few months.

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/[deleted] Dec 04 '24

I would argue that Rust has a less steep learning curve than C++. And it's not even close. If you took a rookie programmer and introduced them to rust and c++, sure, at first c++ will be relatively "easy", but as time goes on the difficulty explodes out of proportion. Rust starts hard but gets easier because its much easier to reason about the program and the state of any one variable at any point in the program.

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/Agitated_Bike3255 Nov 30 '25

Zig will die out in 5 years latest because it is a one man project.

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