3 ms·
> The safety argument simply doesn't register most of the time. Just like Steve said: > Rust is safer than C or C++. (“I never have problems with safety in th
by wereHamster 10y ago
> The safety argument simply doesn't register most of the time.
Just like Steve said:
> Rust is safer than C or C++. (“I never have problems with safety in the C++ code I write” is a common reply.)
The CVE provides a pretty convincing argument that people can't write safe code in C/C++. And improving safety over C/C++ specifically is Rust's raison d'etre (you know, being developed by Mozilla which has a pretty large C/C++ codebase where safety is an important aspect). The bashing isn't based on people merely disliking C/C++. It's based on the fact that we observed 30 years of C/C++ being used in the industry and yet we still discover security holes caused by the same underlying flaws in the language.
Yes, Rust may have other features to offer, too. But safety is a big one and is thus mentioned so often.
- dispose13432 10y agoC++ 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.