4 ms·
Rust is a move-first language. Move is standard; you have to deliberately make anything non-trivial copyable. Rust strongly prefers to be single-assignment and
by Animats 3y ago
Rust is a move-first language. Move is standard; you have to deliberately make anything non-trivial copyable. Rust strongly prefers to be single-assignment and to pass things as read-only references or moves. Those are the right defaults. In C++, the good defaults are all harder, because they were added as afterthoughts to the language.
C++ has been gradually back-porting Rust features, but it provides help only for carefully written new code. You can still get raw pointers out, which breaks safety. To make forward progress with the C++ model, you have to throw stuff out of the language. That breaks too much old code. So they're stuck.
Many, many people, including me, have tried to make C/C++ safer without breaking backwards compatibility too much. It doesn't seem to be possible to do both. You have to disallow some things or the exercise is pointless.
Did this new proposal include array slices for C++? If you have slices, most of the need for pointer arithmetic goes away. But you need either a garbage collector, as in Go, a borrow checker, as in Rust, or restrictive scope rules to track when the underlying array goes away.
- rewmie 3y ago> C++ has been gradually back-porting Rust features, I would hardly say that move semantics, or reusing temporary objects instead of deep copying them, is something invented by Rust. Also, move semantics were introduced in C++ with C++11, which was in the works since the early 2000s. Rust first appeared in 2015. Are you actually trying to claim that C++ in 2011 specified in an international standard features that it back ported from a language that only saw the light of day in 2015? > To make forward progress with the C++ model, you have to throw stuff out of the language. No, not really. Mindlessly removing features only breaks backward compatibility with no reason. We have progress by offering improvements. It's up to the developer to manage how he manages their projects. Mindlessly breaking compatibility prevents that same developer from benefitting from improvements for no reason whatsoever. > Many, many people, including me, have tried to make C/C++ safer without breaking backwards compatibility too much. It doesn't seem to be possible to do both. You have to disallow some things or the exercise is pointless. This is an absurdly silly thing to say. It's a kin to complaining that making Rust safe is pointless because Rust still supports unsafe.
- Animats 3y agoThe safety problems of C/C++ come from the old features, such as null-terminated strings, arrays without size information, and pointer arithmetic. Until there is a will to kill those off, there will not be much forward progress in safety.