3 ms·
> There needs to be some way to sort in place. Sometimes you need to sort a big array and don't want to allocate Your parent isn't saying there shouldn't be mu
by steveklabnik 2y ago
> There needs to be some way to sort in place. Sometimes you need to sort a big array and don't want to allocate
Your parent isn't saying there shouldn't be mutation, just that the mutation should be obvious.
In Rust, the type signature for the in-place sort is
pub fn sort(&mut self)
where
T: Ord,
That `&mut self` lets you know that it's going to mutate.
- josephg 2y agoExactly. And for function parameters, rust also (usually) makes it obvious when you’re passing by value, by reference or by mutable reference: foo(x); // Moves or copies foo(&x); // immutable reference foo(&mut x); // mutable reference I don’t need to look up the signature of foo to understand what happens to my variable. It’s obvious at a glance.
- recursive 2y agoFair point. I guess this is the cost of dynamic languages.