5 ms·
> It has a notoriously monsterous learning curve That learning curve exists in C++ too, it's just hidden under the iceberg of 'interesting' runtime behavior. T
by vvanders 8y ago
> It has a notoriously monsterous learning curve
That learning curve exists in C++ too, it's just hidden under the iceberg of 'interesting' runtime behavior. There's nothing like trying to printf a data race only to have the print call insert a fence and make your data race disappear.
> And in this particular context Rust also still forces you to figure out how to pass parameters and manage memory.
This is a lot simpler in Rust. Everything is value type by default, Box<T> for heap allocations, which even then are managed mostly for you via RAII(yeah I know there's std::unique_ptr but you still also have new, delete, new[], delete[], etc). Parameter types are value, mut ref or const ref. Move semantics are implicit if you have a value type. You don't have const/volatile/etc function qualifiers.
implicit type conversion(esp constructors) can be a total bastard and trip you up in nasty ways. Even more annoying if you're trying to bit-pack or do clever math.
Rust got to learn from a lot of C++'s mistakes and is to me a better language for it.
- kllrnohj 8y ago> This is a lot simpler in Rust. Everything is value type by default, Box<T> for heap allocations, which even then are managed mostly for you via RAII(yeah I know there's std::unique_ptr but you still also have new, delete, new[], delete[], etc). Parameter types are value, mut ref or const ref. Move semantics are implicit if you have a value type. You don't have const/volatile/etc function qualifiers. That's not simpler at all - it's basically the same. C++ is also value type by default and you have to ask for heap allocations. And just like in C++ you have types in Rust that look like stack allocations but aren't, like Vec. So no, it's just value type otherwise Box<T>. That's not true in the slightest. And you need to specify in your function if it's taking ownership or not in addition to whether or not it's pass-by-value or pass-by-reference. Other than new/delete it's the same shit, just a different syntax. Rust got to break backwards compatibility which allowed it to remove a lot of C/C++'s old mistakes, yes, but the raw complexity is still entirely there, and very nearly identical.
- vvanders 8y ago> That's not simpler at all - it's basically the same Oh, you mean like how you have rvalues, lvalues, xvalues, glvalues and prvalues[1]. In Rust you have value, ref and mut ref. You also don't specify ownership of passed pointers. So you need to encode that into your function documentation, as opposed to Rust where only value types can change ownership. > And just like in C++ you have types in Rust that look like stack allocations but aren't, like Vec. Never said anything about that, we're just talking about parameter types here, of course you can have value types take ownership of stack allocations(Box<T>, std::unique_ptr and their variants). > And you need to specify in your function if it's taking ownership or not in addition to whether or not it's pass-by-value or pass-by-reference. Not in the case of Rust, value types are the only thing that can take ownership(even Arc/Rc return value types when you clone()). Refs just allow temporary access in a mutable/const way for the lifecycle of the function. > Rust got to break backwards compatibility which allowed it to remove a lot of C/C++'s old mistakes Thanks for proving my point. I've never seen a C++ codebase that didn't use some of C++'s mistakes. [1] https://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues https://stackoverflow.com/questions/3601602/what-are-rvalues...
- kllrnohj 8y ago> Oh, you mean like how you have rvalues, lvalues, xvalues, glvalues and prvalues[1]. In Rust you have value, ref and mut ref. That is not a reasonable comparison and you know it. rvalues & lvalues are the only things in C++ that you ever care about in the slightest unless you're writing a compiler, and if you're writing a compiler then Rust has things like xvalues, too (how do you think the Drop trait works?)
- vvanders 8y agoAnswer me a simple question, why does std::move exist then? (here's a hint, Rust doesn't need xvlaues because every value already has an associated lifetime)