5 ms·
Rust's complexity isn't accidental unless it's being used for a job where it's overkill. Achieving memory safety in non-GC languages (let alone the degree of ot
by firethief 7y ago
Rust's complexity isn't accidental unless it's being used for a job where it's overkill. Achieving memory safety in non-GC languages (let alone the degree of other static safety Rust enables) is easier in Rust than C++.
- mevile 7y agoThe way I think about it is that Rust exposes all the hard stuff that's hidden in C++. C++ makes things look simpler than they are and eventually you end up in one nightmare scenario after another, because of all the hidden complexity. Rust just shoves all that complexity to the forefront, right in your face, so that you are forced to deal with it and don't end up in nightmare land later.
- codesushi42 7y agoHonest question, what part of Rust is more complex than C++, smart pointers and all? Because it's not evident.
- wiremine 7y agoI'm not a full time Rust developer, so your milage will vary: Rust is a more modern language, so there are a number of modern approaches that Rust uses that C++ can't due to backwards compatibility. And Rust isn't fundamentally an OOP language. I'd say Rust is a bit closer to C than C++, but that's a gross simplification. But I think what Rust does is forces the developer to address application complexity at compile time, instead of finding out about these problems during run time. Things like segfaults, race conditions, etc. are ferreted by the compiler. So, Rust might feel more complex, but in reality it's just forcing you to deal with those issues sooner rather than later.
- tomjakubowski 7y agoAnother gross simplification I like is: Rust is a memory safe C with type classes. (traits)
- codesushi42 7y agoTuring complete templates and inheritance make C++ far more complex I'd say then, even at compile time.
- firethief 7y agoI think Rust is closer to C++ in an important way. Rust and C++ provide abstractions in situations where C spells out the implementation explicitly: e.g. Trait objects (virtual inheritance in C++), lambdas (same in C++), enums (no equivalent in C++). To accomplish similar things in C you'd specify how it will be represented at the machine level, e.g. a struct of function pointers; a function pointer + struct pointer; a union + some way of identifying members. Generally this adds a lot of convenience to the higher-level languages compared to C, but it sacrifices flexibility in the special situations where you need that level of control (e.g. implementing an efficient VM you might want the tag of your object type to be more of a bitfield).
- wiremine 7y agoThose are great concrete comparisons.
- firethief 7y agoLifetimes. In C++ you don't have to think about ownership to make the compiler happy; you only have to worry about that stuff if you want your program not to crash.
- codesushi42 7y agoCan you give an example? Smart pointers make you consider ownership. Or does Rust account for more than that?
- firethief 7y agoRust's ownership model tracks the safety of borrows at compile time in ways C++ can't. You can derive a reference from another reference, and the compiler won't let you do anything to the original object that would leave the derived reference dangling. In C++ there are two different conventions for that: use plain old pointers to represent the borrows, and be careful they don't outlive the owning `unique_ptr`; or use `shared_ptr` to do the bookkeeping at runtime (also available in Rust, as Rc/Arc).
- codesushi42 7y agoGot it, thanks for the explanation. So C++ programmers are able to subvert the upfront complexity by ignoring C++ 11 features then, going straight to raw pointers.
- unrealhoang 7y agoThat's exactly why I use Rust, I can not be sure when I get enough confident with C++ to not make my program crash in unexpected ways.