Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> lacks the basic safety features to avoid dangling pointers

It doesn't. Unfortunately, C++ programmers choose not to use basic safety features for performance reasons (or aesthetics, or disagreement with the idea that a language should take into account that a programmer might make a mistake, but at least performance is a good one), but C++ actually has quite a few tricks to prevent the memory management issues that cause C/C++ bugs.

Using modern C++ safety features won't completely prevent bugs and memory issues, just like using Rust won't, but the mess that causes the worst bugs is the result of a choice, not the language itself.



Tell that to the designers of the C++ standard library, and the new features being added. They're the ones that keep adding new features that depend on references and pointers instead of std::shared_ptr or std::unique_ptr.


I think one problem here is that a lot of codebases have their own smart pointers and unfortunately the only currency type is the unsafe one :(


I don't think this is the only reason. If it were, they could easily have added overloads that work with both std smart pointers and with plain pointers for compatibility. Or they could add pointer type template parameters, maybe with concepts for the right ownership semantics.


That would be too complex. I don't think C++ developers would be able to handle it


shared_ptr and unique_ptr aren’t useful for reasoning about the lifetimes of stack-based objects (unless you’re willing to require that such objects always be dynamically allocated, which is often not a reasonable requirement).


Do these “modern C++ safety features” actually exist in any usable manner?

string_view, for example, is very modern and is utterly and completely unsafe.


> the mess that causes the worst bugs is the result of a choice, not the language itself.

Even the creator of the language admitted that "just write better code bro" approach doesn't work.


Has he? He at least used to be the biggest proponent of it, "just follow these standards and development practices that I had to meticulously develop for the US military, that no tool can automatically check, and you'll be fine!".


Yes, it writes in the slide 6 of presentation that Bjarne himself created: https://github.com/CppCon/CppCon2023/blob/main/Presentations...




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: