I did. And I don't like it. I don't like &mut
and would, probably, prefer something else (&my
, &only
or &uniq
) but I was trying to imagine why would I want that middle possibility (unique reference which doesn't give you the ability to mutate object)… and couldn't. All the examples which I can imagine are extremely convoluted and strange.
Maybe you can show where would you use &uniq
is std
and why? It's large library, if there are no place where would you apply these… then are they really useful?
Why? On the contrary, this article explains very well why you need immutability by default. I mean: why would you want &x
to be easier to write that &my x
(&mut x
, &own x
, or &uniq x
).
It's true that marks on local variables (let
vs let mut
) are not too important. I still prefer let
, but not strongly, these are not too much important.
But when you call functions and build larger program from these functions you really want to avoid shared mutable state, if possible, and since &T
references can be shared and &mut T
can not be shared… &T
is better as default.
If you have more than two observers, then it becomes very important that they both “notice” change at the same time.
Thus Rc<T>
or Arc<T>
or some other form of shared mutability implies that “change ⇨ notification ⇨ action” protocol. Which you need to invent and follow.
But if you have something immutable or if you are the only observer, then there are no need to synchronise changes!
If object is immutable then it doesn't change and we don't have the need to synchronise anything.
And if observer is unique then we have no need to notify anyone because there are no one to notify!