The Problem with C++ Safety: Modern C++ Is a Mindset, Not a Standard

4 points by nrposner


BenjaminRi

"Modern C++" is a meme at this point. When C++11 came out, everyone talked about modern C++. Back then, it was justified - move semantics were a real and significant innovation. But here we are, one and a half decades later, still talking about "modern C++". Nobody can tell me what "modern C++" is anymore. Is it modern C++ if I use C++20's spaceship operator? Or if I use C++23's std::print? Compared to other languages, nothing about C++ feels modern anymore. Not the type system, not the memory handling and lifetimes, not the toolchains, not the build environment and dependency management. If anything, we've been waiting for decades for features that other languages had all along. Some shipped, like concepts and modules, though module support is apparently still very spotty. Other absolutely crucial features like compile-time reflection and memory safety are still completely unavailable. Perhaps we should start calling it "contemporary C++" to make explicit the fact that nothing about it is modern and that by now, everyone should use the primitives that were new decades ago.

nrposner

We saw the first part of this post a couple weeks ago, and I was hoping there was something more substantive in part 2.

On the one hand, I’m certainly in agreement that C++ education materials could improve: I sometimes wonder how many person-hours of work could be avoided by revamping the UI/UX of cppreference.com.

All the same, declaring that it’s all about mindset and that to be safe people should just use more standard library functions feels quite weak. Those with experience should correct me if I’m wrong, but talking to the C++ devs in my life tells me that there’s a long memory of being bitten by innocent-looking standard library constructs, both in safety and the performance that a lot of C++ projects call for.

hunger

Well, what else could it be?

Its not as if C++ made significant progress towards becoming safer in C++26. In fact they do not even want to become memory-safe, just "memory-safer", whatever that is even supposed to mean.