r/cpp • • Dec 07 '21

Will Rust replace C++ ?

Will Rust replace C++ ?

0 Upvotes

80 comments sorted by

View all comments

11

u/eyes-are-fading-blue Dec 07 '21

Unlikely in the foreseeable future. If either C++ compiler or tooling around it (linters/static analysis) catches up with Rust compiler in terms of race condition/lifetime guarantees, then there is no chance of Rust replacing C++. Now how possible this is, I am not sure.

2

u/Full-Spectral Dec 07 '21

Not really possible. And, even if it got close, the difference between having these things caught immediately during compile vs. having to run a 10 minute analysis pass to hope to catch close to the same amount of issues is huge. It will always be a band-aid with C++.

4

u/eyes-are-fading-blue Dec 07 '21

Care to elaborate why it is impossible?

2

u/Full-Spectral Dec 07 '21 edited Dec 07 '21

C++ is about performance over safety these days. It would have to fundamentally change in order to give the tools enough information compete with Rust on the memory safety front. And it's just not going to fundamentally change at this point.

The technical reasons are many, and they've been gone over many times before. I'm not going to reiterate them here. Many of the problems are in the STL, but since almost everyone that uses C++ will use the STL (and yell down anyone who tries to create something better) they are one and the same for the purposes of this argument.

11

u/johannes1971 Dec 07 '21

Classes like unique_ptr, shared_ptr, and vector have done a great deal for making C++ safer (to the point that I no longer think of memory safety as an issue). Additional new classes or language features can help in making C++ even safer. As with so many things, it doesn't have to be perfect; it just has to be good enough.

2

u/Full-Spectral Dec 07 '21

Well, when you start getting completely inexplicable crash reports from the field, how good is good enough?

5

u/eyes-are-fading-blue Dec 07 '21

Can you then give link to these discussions? I made a small research before that post, I have seen people claiming this is theoretically possible.

I am also surprised the same problems are also seen in STL. STL's biggest problem is ABI and compatibility issues but a linter embedded in compiler or a static analysis tool is executed before code generation.

-1

u/Full-Spectral Dec 07 '21 edited Dec 07 '21

I haven't kept a list of links of such discussions. You can find them here in this section if you look. And of course theoretically possible doesn't mean practical. If it takes orders of magnitude more time to get 75% of the benefits, then it's not really competitive.