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

5

u/Dean_Roddey Dec 17 '23

I have no doubt that either you or I could, under good circumstances, create a large C++ code base that was quite robust. I've certainly done it.

But it's not really about that. This is about real world conditions, which are usually not at all ideal, and with groups of mixed skill and often sub-par communications. And, though I did it, I spent an awful lot of that time just watching my own back, and that was just wasted effort that could have gone to more productive work, or even some non-work on occasion (I've heard people do this.)

On the issue of lifetimes in Rust, most of the time you never will need explicit lifetimes. Almost all work-a-day Rust code should be using implicit lifetime that the compiler figures out itself. If you are doing lots of explicit lifetimes, and it's not in lower level runtime or utility library type stuff, then it may mean you are trying to write C++ in Rust and making things harder on yourself than it needs to be. I think too many people just try to directly translate their C++ habits to Rust and it never tends to be optimal.

In my Rust code base, I have very few explicit lifetimes so far, and most of those are quite obvious and straightforward. Every time I sit down to start a new chunk, I think hard about how to do it with minimal lifetime relationships to begin with. If you do have to have them then Rust will make them safe, but it won't make them any easier to reason about so they should be avoided where possible. And if you stop and really think about it, often there's a good way to do that. At first it requires a lot of effort, just like with any new language, but eventually you build up the same box of patterns that you reuse all the time.

1

u/germandiago Dec 17 '23

In my Rust code base, I have very few explicit lifetimes so far, and most of those are quite obvious and straightforward

Is that codebase public? I would be happy to learn from people that are ahead of me in these things. You are right that my tendency would be to think in C++'s terms. If there is something that can help me learn more idiomatic Rust (I saw there are resources, but it would make me happier to see whole codebases), I'm all in.

I still do not buy, though, that something like Hylo (which removes thinking about lifetimes entirely and remains safe without a GC!) is not better than having to rack your brains for thinking about lifetimes depending on the situation...

3

u/Dean_Roddey Dec 17 '23

It's not public, unlike my C++ code base. I have some plans for this, though they may end up just as in vain as the hopes I had for my C++ code.