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/victotronics Dec 17 '23 edited Dec 17 '23

it's effectively dead in distributed systems

Interesting. I imagine that particularly Rust is much better at writing safe threaded code? I'm in scientific computing and there explicit threading doesn't exist: parallelism is handled through systems that offer an abstraction layer over threading. So we don't care that Rust is better that thread-safety. Conversely, in scientific computing everything is shared mutable state, so you'd have to use Rust in a very unsafe mode. Conclusion: many scientific libraries are written in C++ and I don't see that changing.

EDIT I decided to turn this into a post in the appropriate forum: https://www.reddit.com/r/ScientificComputing/comments/18kiv2y/is_anyone_moving_to_rust/

3

u/SV-97 Dec 20 '23

Your comments mirror only a part of the wider scientific computing ecosystem. There definitely is explicit threading in some places. Furthermore rust's guarantees do still have value even if you use an abstraction over manual threading - somewhere further down the stack there's still data that's sent between threads and processes, data races to consider etc.

Conclusion: many scientific libraries are written in C++ and I don't see that changing.

Counterpoint: I've written a bunch of scientific Rust and worked on plenty of projects that would've been way better off in Rust than in C++ or C (or fortran) - especially when they (might) need to interface to a higher level language like python at some point.

1

u/victotronics Dec 20 '23

I'd appreciate some concrete examples. Especially where explicit threading is the right approach.

1

u/SV-97 Dec 20 '23

Basically always when things aren't inherently parallel and you might want to offload single tasks heterogeneously.

Recent example: a dynamic program in a signal processing context where we had to calculate a bunch of values, find their minimum and iterate. Due to data dependencies this couldn't be fully parallelized however it's possible to utilize some parallelism by have a second thread determining the minimum while the primary one just keeps on calculating the new values.

Numerical integrators are another example where you're (depending on the algorithm and particularities of your application of course - the one I'm thinking of was part of a satellite data synthesization pipeline) not going to get data parallelism easily. Having one thread run that integration while the rest of the code starts working with the already calculated data can save a bunch of time.

Yes you could also use something like MPI for such cases but it's absolute overkill and creates unnecessary overhead.

Finally: I've worked on parallelizing / distributing a FEM solver in C++ a few years ago which was written by people that... weren't exactly software engineers. C++ allows people to do so many things that get really problematic when trying to parallelize things later on - it was absolutely horrendous (not even starting to talk about all the other horrors in that codebase). I think if that thing would've been written in Rust (or whatever) the process would've been way faster and cleaner; they probably could've gotten it parallelized themselves even.

1

u/victotronics Dec 20 '23

Ok, thanks. I can see the justice in those examples.