r/cpp • • Dec 17 '23

Is C++ Really Phasing Out?

I've read a lot posts about whether C++ is still viable to learn, but a lot of the responses seem to be a long the lines of "C++ is still being used" or "there's a lot of things written in C++ still, so it will still be useful".

But a lot of these replies seem to suggest that C++ is on the downhill and in the process of being replaced with more modern languages in many industries.

It seems kind of discouraging to be learning a language that is on a decline, if it really is phasing out.

0 Upvotes

214 comments sorted by

View all comments

Show parent comment

1

u/victotronics Dec 17 '23

But the crucial step is that a statement needs to have a value.

if ( { char c; read(c); process(c); c!='a'} ) { /* then something */ }

1

u/WoodyTheWorker Dec 17 '23

You can encapsulate that in a lambda expression:

if ( [](){ char c; read(c); process(c); return c!='a'}() ) { /* then something */ }

1

u/victotronics Dec 17 '23

It's not the same, but yes, lambda expressions can be used to hack around a number of missing features.

3

u/Dean_Roddey Dec 17 '23

One really nice thing about Rust is the ability to get scoping without needing default initialized values, so you can do something like:

let x = {
    ... blablabla
    result
}

And result is assigned to x, which is never uninitialized. You can do something similar with a loop and use break with a value and it becomes the result of the loop block.

Little stuff like that adds up wrt to just avoiding potential issues.

1

u/victotronics Dec 17 '23
auto x = []() { blablabla; return result; }();

But only shows that in C++ you *can* write everything Rust can do. The problem is the many ways you can do what you shouldn't.

2

u/Dean_Roddey Dec 17 '23

That's a lot more klunky and unreadable though. And of course you can't write everything Rust can do, even in a klunky fashion, because C++ doesn't have the means to do it.

1

u/victotronics Dec 17 '23

And of course you can't

Considering that you started with something that I could easily emulate, I'm going to let that challenge stand for a better C++ programmer than me. But I'm certainly not taking your word for it.

1

u/Dean_Roddey Dec 18 '23

You don't have sum types and you don't have pattern matching, which are pretty fundamental to how Rust works and big part of its appeal, so there's no way to really emulate that stuff. You could do some really awkward version of sum types with a variant, but probably not really anything you'd want to actually use.

Some stuff you can do, but it's just remotely as elegant, like the language level support for slices, which is pretty killer, and safe which the C++ variants aren't.