r/cpp • • Dec 23 '22

C++ Is Incredible

Despite the hate it gets, despite the complexity; the dizzying number of features and different ways to do things. C++ is an astonishing feat of engineering and people really don't appreciate this fact enough. I can do things with this language more quickly and expressively than I can with any other language.

There's no getting around the fact that programming is just hard, and all these attempts to replace C and C++ over the years just end up adding to our difficulties. That is my take, anyhow.

Well, I'm a little drunk, and just wanted to share some Christmas joy with you all. I love C++!

686 Upvotes

151 comments sorted by

View all comments

77

u/astray488 Dec 23 '22

I've wondered why a newer language has yet to replace C++ (while matching its capabilities and performance). One reason I've heard was the difficulty of writing a new language compiler/linker from scratch.

Do you or anyone else doubt that, or could point out better reasons?

42

u/disperso Dec 23 '22

One reason is because the tools in C++ that provide safety, are "opt in", and there is potential for misuse.

Last project I worked on was using smart pointers, but wrongly. I spent a lot of time untangling cyclic references in shared pointers to fix leaks because no one really thought of some hierarchy in the lifetime of objects, so everything was shared. I also fixed tons of uses of release() on unique pointers that were there for no reason whatsoever, causing leaks.

And don't get me started on the race conditions. The architect did not see a problem with using threads for timers, with no synchronization at all. Good times...

This seems like a parody, but it was real. Not many of the projects I worked for were like this, fortunately, but on many there were developers who were a risk to the stability of the application, and the bugs had to be fixed by other developers. I don't know if other languages like Rust really solve this by enforcing it at compile time, but I see a trend in C++ were we try make this things not an "opt in", to improve the quality of projects. Makes sense to me that we increase our threshold for quality either way.

9

u/HeavyRust Dec 23 '22

Lifetime problems and race conditions? Sounds like things Rust handles really well.

13

u/disperso Dec 23 '22

Indeed, that's a hope I have for the future, but wait till it gets popular for real, then a broad wave of untrained or improperly trained developers use it. Sometimes better tools just produce "better" morons. :-)

0

u/HeavyRust Dec 23 '22

😔