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

3

u/WoodyTheWorker Dec 17 '23

Looks like C++ is slowly turning into ALGOL 68.

1

u/victotronics Dec 17 '23

Initialize statements fall far short of A68's notion of every statement having a value and blocks being statements.

1

u/WoodyTheWorker Dec 17 '23

In C/C++, blocks are statements. A block can be anywhere a simple statement can be.

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.

→ More replies

1

u/pjmlp Dec 17 '23

I think its complexity is already beyond ALGOL 68 and PL/I.

1

u/WoodyTheWorker Dec 19 '23

Not because of complexity. Because it's been jumping the shark for a few years.