top | item 38943383

(no title)

anordal | 2 years ago

I'm skeptical because C++ is a slippery slope. Glad to see they are going for templates and concepts, and not constructors and destructors.

Yes, what C++ is supposedly good for – RAII, it actually got a little wrong:

1. Default construction / value initialization: Causes lots of initialization before assignment that is obviously unnecessary. Try allocating a buffer: `std::make_unique<char[]>` surprisingly memsets the buffer.

2. Constructors: No way to fail without exceptions. That buffer example again: Without exceptions, `std::make_unique<char[]>` will actually attempt to memset a nullptr on allocation failure … before your nullptr check (which btw makes the compiler entitled to delete your nullptr check as well).

3. Move is a (burdensome) runtime state that mandates nullability.

4. Destructors: Can't take arguments, forcing objects to contain implicit references to each other.

Rust's affine type system fixes 1-3, but not 4, which only a linear type system could: https://en.wikipedia.org/wiki/Substructural_type_system#The_...

discuss

order