Mutation - Part 0: Intro
For a first programming post, I have chosen an innocent-looking topic, regarding Rust’s mut
keyword:
What does mut
truly mean? what does it do?
For starters, let’s quote TRPL1:
Mutability, the ability to change something
Hum, it looks like they got it the other way around. Let’s fix it:
Mutability, the
abilitytochangesomethingMutability, the property of being change-able
Note the change in the grammatical aspect: if a mutator modifies a mutatee, the mutability required for it to be possible is the mutatee’s one (and not the mutator’s).
Another possible point of view is that mutability is a property of the pair (mutator, mutatee). But since, in the case of a program, there is only one mutator (the (imperative) programmer), it all boils down to the same thing.
X is said mutable when it can be modified, and only then.
So the following question is, what does modifying mean?
Ok, we could keep going on, but let’s try not to drift too much, shall we? So I will only talk about “modifying X” when X is a variable.
EDIT: This is where I realise that a single blog post will not suffice, so this is now a blog post series.