←back to thread

In Defense of C++

(dayvster.com)
185 points todsacerdoti | 7 comments | | HN request time: 0.001s | source | bottom
1. kronicum2025 ◴[] No.45268740[source]
The safety part in this article is incorrect. There's a google doc somewhere where Google did an internal experiment and determined that safety c annot be achieved in C++ without an owning reference (essentially what Rust has).
replies(1): >>45274115 #
2. Attrecomet ◴[] No.45274115[source]
Am I missing anything in the article about this problem in particular? Owning references are a part of modern C++, which should be covered by the author's arguments.
replies(3): >>45276325 #>>45277006 #>>45348935 #
3. aw1621107 ◴[] No.45276325[source]
> Owning references are a part of modern C++

Maybe we're thinking of different things, but I don't think C++ has owning references, modern or not? There's regular references (&) which are definitely not owning, and owning pointers (unique_ptr and friends), but neither of those quite match Rust's &.

replies(1): >>45300122 #
4. steveklabnik ◴[] No.45277006[source]
I think your parent may be slightly confused, in the sense of terminology: "owning reference" is a contradiction in Rust terms.

Here's the document I believe your parent is referring to: https://docs.google.com/document/d/e/2PACX-1vSt2VB1zQAJ6JDMa...

The claim in the article:

> Yes, C++ can be made safer; in fact, it can even be made memory safe.

The claim from this document:

> We attempted to represent ownership and borrowing through the C++ type system, however the language does not lend itself to this. Thus memory safety in C++ would need to be achieved through runtime checks.

It doesn't use "owning reference" anywhere.

replies(1): >>45300140 #
5. Attrecomet ◴[] No.45300122{3}[source]
Ah, okay, that is a good point. I was not aware of that subtle difference, and replaced "owning reference" with "owning pointer" in my mind.
6. Attrecomet ◴[] No.45300140{3}[source]
Thanks for the clarification!

However, I also got confused, and just subsituted "pointer" for "reference" in my head. References, apart from smart pointers, are indeed a problem for memory safety.

7. kronicum2025 ◴[] No.45348935[source]
I meant to say exclusively owned references.