1-basics: variability vs mutability
eddyb opened this issue · 6 comments
I already tried to summarize it at rust-lang/book#276 (comment) for the second-edition book.
But the very short version of it is:
- "variable" => "may not have the same value every time" (e.g. user input)
- "mutable" => "the value may further change during the scope of the variable"
And the reason "immutable variable" is confusing is because all variables in some languages are mutable by default (i.e. without const
or final
), not because "variable" implies mutability.
(You may already know all of this, but I wanted to make sure we're not promoting "it is so because we say so" explanations, when the terms we use are consistent with other disciplines, e.g. mathematics)
Good point. I'm trying to speak to the usual sense of 'variable' in programming, but it's more the mathematical sense here. And 'variable' vs 'constant' is the important thing.
@stevedonovan They're the same meaning! It's just that the defaults differ, like with references.
I've fleshed it out a little. Yes, variables are variables. But the mutable default that is so common confuses people.
Should this be closed with the changes you made? They seems good enough.
"immutable variable" is an oxymoronic contradiction in normal english.