Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1-basics: variability vs mutability #13

Closed
eddyb opened this issue Mar 20, 2017 · 6 comments
Closed

1-basics: variability vs mutability #13

eddyb opened this issue Mar 20, 2017 · 6 comments

Comments

@eddyb
Copy link

eddyb commented Mar 20, 2017

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)

@stevedonovan
Copy link
Owner

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.

@eddyb
Copy link
Author

eddyb commented Mar 21, 2017

@stevedonovan They're the same meaning! It's just that the defaults differ, like with references.

@stevedonovan
Copy link
Owner

I've fleshed it out a little. Yes, variables are variables. But the mutable default that is so common confuses people.

@andradei
Copy link

andradei commented Mar 29, 2017

Should this be closed with the changes you made? They seems good enough.

@pannous
Copy link

pannous commented Jan 19, 2018

"immutable variable" is an oxymoronic contradiction in normal english.

@eddyb
Copy link
Author

eddyb commented Jan 19, 2018

@pannous In some sense "variable" is short for "variable binding" - the value inside is the variable, and what you're mutating is the "variable binding", not the value (which varies for a different reason than mutation - e.g. function arguments can differ between calls).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants