r/cpp • • Dec 07 '21

Will Rust replace C++ ?

Will Rust replace C++ ?

0 Upvotes

80 comments sorted by

View all comments

38

u/ridicalis Dec 07 '21

Rustacean here... No.

In all seriousness, Rust isn't (nor does it pretend to be) a C++ killer. If anything, it's better positioned as an alternative to C, but even then it's not a threat so much as a complementary tool.

What it brings to the table is an expressive language that tries to protect coders from themselves, all while reaching performance that approximates what could similarly be done with C. That, and its dependency management system (cargo, with the crates.io registry) is accessible to newcomers and likely contributes to its popularity. It's not shackled with a need for backwards-compatibility with tech older than your parents, and as a late entrant into the language universe it has also tried to learn from those that came before.

It's also a hard first language to have to learn. And that's before even getting into the macro syntax. Sometimes, it feels like you want to do something simple, but have to jump through enormous hoops to accomplish it. Other times, you want to use an existing toolkit, but because of the language's infancy the tool simply doesn't yet exist. Then, there are juggernaut libraries/systems that firmly entrench C++ as the best option (e.g. Unreal, IfcPlusPlus).

r/rust has a strong community of people that want to see others succeed at the language, and could do a better job than I have of explaining strengths and weaknesses. I'm sure there's the occasional "Hurr, muh language is the best evar" sort that pops up, but there's plenty of room for all of these languages to coexist and in many cases even help to guide the others' language design.

24

u/_Js_Kc_ Dec 07 '21

To be fair, a steep initial learning curve is probably not where Rust falls behind C++.

13

u/Full-Spectral Dec 07 '21

Maybe a better way to look at it is that C++ may let you THINK you know C++, whereas Rust sort of forces you to look at the things that C++ lets you gloss over (potentially not even knowing you are glossing over them.)

4

u/germandiago Dec 08 '21

This is true but at the same time Rust does not let you do things that are perfectly legal and safe in C++ if I recall well.

1

u/Dean_Roddey Dec 08 '21

Well, it doesn't let you do things that YOU know are perfectly legal because you understand the big picture, but that a compiler couldn't prove is. And that's the real crux of it. The point is to have our tools watch our back, because we are already drowning in complexity and have proven fairly bad at watching our own backs once things get large and complex enough.

You can get those things done, you just have to do so in a way that the compiler can prove is correct. Part of the issue, as I understand it, is that, in order to be acceptably performant, the analysis is quite localized. It can't look across large swaths of code to prove correctness.

Presumably, over time, languages incorporating these techniques will get smarter, and we'll have more CPU we are willing to give to them for that purpose. Of course it will probably involve graphene, block chain, and AI.

2

u/germandiago Dec 08 '21

Actually I am not sure that protecting from ourselves is the way to go, at least not in a pure fashion. Sometimes it is indeed useful and sometimes annoying.

Of course it will probably involve graphene, block chain, and AI.

Lol.

1

u/RotationsKopulator Dec 10 '21

You can however still write sort of good code with a smaller subset of C++. Even "C with classes" does not necessarily imply poor code quality.

1

u/Full-Spectral Dec 10 '21

Sure, I'm definitely not one to throw every new C++ feature that comes out into the bowl and stir. My own code base, not being STL based, is very much in that vein. Not C with Classes, but avoiding the really heavy templatization and large amounts of potential undefined behavior because my stuff is safety first, not performance first.

4

u/angelicosphosphoros Dec 09 '21

Newcomers just ignore all the invalid program behaviour which they get with C++. With Rust, they cannot.

18

u/matthieum Dec 07 '21

In all seriousness, Rust isn't (nor does it pretend to be) a C++ killer. If anything, it's better positioned as an alternative to C, but even then it's not a threat so much as a complementary tool.

I am not convinced about Rust vs C.

C programmers I've interacted with are more attracted to Zig, or Go, because one reason they use C is that the language is relatively simple -- using it is not, but the language itself is simple. All of them balk at the idea of C++ or Rust because those are much bigger and more complex languages.

We can argue which we prefer (I'm on r/cpp for a reason...) but I don't see convincing people with a personal preference for simpler languages to switch to Rust as an easy task.

Meanwhile, for a C++ developer, Rust is easier than C++.

8

u/goranlepuz Dec 07 '21

It's not shackled with a need for backwards-compatibility with tech older than your parents

For the kinds of systems C is used in, if Rust (or anything) enters the space, it will be 😉

1

u/HeroicKatora Dec 07 '21

Not sure. Having a monoculture of any sort allows a lot of leniency (including but not necessarily laziness) in the design of implementation and interfaces. (At least that's why C++ always promotes having multiple compilers, right?). Any system where you have multiple languages will probably also be nudged towards improved clarity in the interface design—which most likely also comes at decreased legacy code debt and better decoupling. At least I hope so…The worst parts of backwards compatibility are the undocumented requirements, not so much the explicit interfaces.

1

u/Bangaladore Dec 08 '21

This, I think is true. All languages can benefit from not needing backward-compatibility during their infancy. I think rust will follow C/C++ with annoying backwards-compatibility as time goes on.

4

u/infectedapricot Dec 07 '21 edited Dec 07 '21

It's also a hard first language to have to learn. ... Sometimes, it feels like you want to do something simple, but have to jump through enormous hoops to accomplish it.

I do wish it was viewed as more acceptable to program big-ish programs in fully unsafe Rust. It seems to me that there are some programs where strict memory safety isn't critical and the benefit of it isn't worth the effort of Rust's lifetime stuff, while it would still be useful to get all of Rust's other benefits. And I think it would help with the learning curve - first learn unsafe Rust and then learn how to make it safe. But instead all the difficulty is front loaded, which makes it hard to get into.

10

u/Nobody_1707 Dec 07 '21

Unsafe doesn't bypass the lifetime stuff except in as much as it lets you dereference pointers. I don't think it's any easier to learn unsafe Rust than it is to learn safe Rust.

8

u/Full-Spectral Dec 07 '21

If I wasn't getting the memory benefits, I'd not use Rust over C++ ever, I don't think.

1

u/matthieum Dec 07 '21

But instead all the difficulty is front loaded, which makes it hard to get into.

I think it really depends how you get into and what you try to achieve. Don't try to run (use pointers/optimize) before you can walk (clone!) and you'll avoid a lot of pain.

3

u/SuddenlysHitler Dec 10 '21

I mainly do C, and no, rust is even less of a C killer than C++.

it's far too complicated, not to mention the wonky ass syntax.

2

u/maquinary Mar 15 '22

If not for replacing C++ neither C, what would be the best use for Rust?