5 ms·
> Rust has approximately 1.5 advantages over C/C++ I can think of at least 3 that deserve a whole integral bullet point: * ADTs * Hindley-Milner/typeclass ty
by wyager 2y ago
> Rust has approximately 1.5 advantages over C/C++
I can think of at least 3 that deserve a whole integral bullet point:
* ADTs
* Hindley-Milner/typeclass type system
* Lifetimes and affine types
And a bunch of minor ones that count for something like 0.1-0.5 of an advantage.
I would guess we're on track for a majority-of-new-code switchover point somewhere around 2030-2035.
- milesrout 2y agoMaybe he meant net advantages. Rust has some advantages (ADTs, no constructors, no overloading, no preprocessor, well thought out set of string types) and some disadvantages (compile times, debug performance, heaps of wrapper cruft to step through when debugging, explicit lifetimes, pervasive type inference, ad-hoc polymorphism, no ABI stability, poor support for dynamic linking, anemic standard library, pervasive one-element-thinking encouraging millions of separate allocations all over the place, culture of simplifying code by adding copying and reallocation everywhere because the borrow checker makes sharing verbose and difficult ("just use clone"), general complexity, dramatic and dogmatic community with a penchant for social media bullying (eg serde, actix)). What is an advantage or a disadvantage depends on who you are. Personally, I find the disadvantages (as I see them) outweigh the advantages. Others believe that some of those disadvantages are actually good things. And some of them depend on whether you are comparing to C or C++: compared to C, Rust has many disadvantages, but C++ has many of the same disadvantages, and often is worse. I don't think Rust will ever have more new code being written in it than C and C++ combined. I doubt it will overtake either individually.
- amluto 2y ago> compile times C++, especially “modern” C++, can have truly horrible compile times. The lack of a usable module system makes it worse. Variadic templates helped some. Fold expressions will help some. I expect concepts and if constexpr and such to help some: relying on SFINAE never did the compiler any favors. But, in general, C++ template programming is quite nasty for compile times.
- milesrout 2y agoYes as I said "And some of them depend on whether you are comparing to C or C++: compared to C, Rust has many disadvantages, but C++ has many of the same disadvantages, and often is worse." C++ compile times can be as bad as Rust's or worse. It does depend on how you structure things and how much you use templates. You don't need to have 10 layers of "zero cost abstraction" around everything. But that is the "proper" way to use it and what is now taught, so there is a lot of it out there and the standard library does it pervasively. Variadic templates don't fix much compared to just writing straight line code or doing a tiny bit more work at runtime using stdarg.h.
- amluto 2y agoVariadic templates help quite a lot compared to what older libraries did or even still do to approximate them. Check out boost::variant’s shenanigans — I recall a single-line file that includes <boost/variant.hpp> and doesn’t even instantiate the variant template taking several seconds to compile.
- kobebrookskC3 2y agoall those advantages and disadvantages you list are basically insignificant compared to rust being memory safe by default and c/c++ not. governments aren't bugging projects about any of those, but are about memory safety.
- milesrout 2y agoYou might think so. I strongly disagree. I think Rust's supposed memory safety advantages are a distraction. If people really cared about that above all else they would use a memory-safe language, which Rust is not, such as Java or Python or Haskell or something. There are tons. Governments aren't "bugging" anyone about memory safety and if they were, they wouldn't want you to use Rust. Rust isn't memory-safe.
- oneshtein 2y agoSafe Rust is memory-safe enough for practical needs, while maintaining top performance.
- menaerus 2y agoIs it still safe even if it depends on the dependencies which are not safe?
- kobebrookskC3 2y agoseems pretty safe in practice https://security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html#fnref3 https://security.googleblog.com/2024/09/eliminating-memory-s...
- menaerus 2y agoI know it's an unpopular opinion but tbh those Google security blogs always read more as a marketing material than engineering effort. Why I think so it's because statistics always has two side of the coins - if you want to make something look better or worse than it really is, it's trivial to do so. There's simply not enough data or methodology or different angles taken for me personally to take these blogs as a very relevant source of information but YMMV. We are all different.
- robocat 2y agoWould C, could C, implement those features?
- oneshtein 2y ago* unsafe blocks for unsafe code * Memory safety in safe code * Fearless concurrency. * match operator and destructuring