|
|
|
|
|
by alpaca128
1969 days ago
|
|
> Or even better, if both is the same. That makes it just less transparent. You still have to be
careful and know the difference or one day you unintentionally
create a shallow copy of an object and now you've got a bug the
runtime won't warn about. Yes, Rust is more complicated and
harder to get into in those areas, but in return it's not as
ambiguous. I know that calling `clone()` will always do just that,
no edge cases, and even if I were wrong the compiler would
immediately tell me because of a type mismatch. Realistically I don't think any of the two approaches is
significantly faster. But I know what I find more consistent and
less frustrating to debug. |
|
However, if you forget about Rust specifics, then things look different. E.g. by simply having the constraint of complete immutability, there is no reason to differ between an object identity and its deep content anymore - it will just be always the same. Of course that means no mutation and hence reduced performance for certain things, which is why Rust doesn't do it.