3 ms·
C++ can be safe. Just use only safe pointers and vectors. The thing is that rust does two things: 1. Safety 2. FP style code ("magic") I wouldn't mind #1, b
by dispose13432 10y ago
C++ can be safe. Just use only safe pointers and vectors.
The thing is that rust does two things:
1. Safety
2. FP style code ("magic")
I wouldn't mind #1, but #2 kind of turns me off.
- wereHamster 10y ago> C++ can be safe. Just use only safe pointers and vectors. Defaults matter. In C++ safety is opt-in, you have to explicitly chose safety, the default is unsafe code. Rust is opposite, safety is opt-out, you have to explicitly use 'unsafe' functions to write unsafe code. Take a guess which strategy makes junior developers write better code.
- dispose13432 10y ago>Take a guess which strategy makes junior developers write better code. An org can mandate use of only safe pointers.
- pjmlp 10y agoYes, but my experience at enterprise level, is that no one does.
- pjmlp 10y agoC++ can be safe, and I usually make sure to use those features when I need to integrate C++ code within JVM/.NET applications. However that is a personal option, I seldom have seen such options in enterprise code.
- steveklabnik 10y agoSafe pointers aren't guaranteed safe. If you move a uniq_ptr, you get nullptr, which can be dereferenced. You'll get zero help from lints, as this is defined behavior by the standard, yet you'll still be having UB. In Rust it's a compile-time error.
- dikaiosune 10y agoLast I checked it's still quite easy to invalidate a std::vector's iterator in "safe" C++. Is that no longer the case?
- Manishearth 10y agoStill possible. There is no "safe subset" of C++. There is a safer subset, which is usually safe. One usually ends up using lots of std::shared_ptr anyway.