3 ms·
I'd argue the exact opposite. Languages that don't have a concept of ownership, and a borrow checker, and don't explicitly say if they want ownership, a referen
by fasterthanlime 6y ago
I'd argue the exact opposite. Languages that don't have a concept of ownership, and a borrow checker, and don't explicitly say if they want ownership, a reference, or a mutable reference, force you to keep all of these details in your head.
Here, if I have a `&T` and I try to call a function that has a `&mut T`, the compiler will tell me that's not gonna work - and then I can pick whether I want my function to take a `&mut T`, or if I want to make a clone and modify that, etc.
There's a learning curve, it's a set of habits to adopt, but once you embrace it it's really hard to go back to languages that don't have it! (See the rest of the comments for testimonials)
- millstone 6y agoI think both points are right. There's times when it's useful and desirable to be specific about lifetimes, and there's also times where it's annoying noise. Bignum arithmetic is an example of the latter. You want to just work with numbers, and in Python you can, but in Rust you must clutter your code with lifetimes and borrows and clones. Swift's plan to allow gradual, opt-in lifetime annotations seems really interesting, if it works.
- CDSlice 6y agoBignum arithmetic actually is pretty simple in Rust if you use the right library. Rug[0] makes using bignums look almost just like using native numbers through operator overloading. [0] https://crates.io/crates/rug https://crates.io/crates/rug
- millstone 6y agoThe operator overloading is nice but you still get smacked in the face right away by the borrow checker. Simple stuff like this won't compile ("use of moved value"): let a = Integer::from(10); let b = a + a;
- smmalis37 6y agolet b = &a + &a; will work, but I agree it's unfortunate that this is necessary.
- pimeys 6y agoThis would work if `Integer` would implement the `Copy` trait. But I guess that type is heavy enough for it to be too expensive, therefore forcing you to explicitly call `clone()`.
- Measter 6y agoThat `Integer` type can't implement `Copy` because it manages a resource, meaning you can't just do a simple memcpy of the type.