by ynik · 3y ago · 0 comments
This article explains the uniqueness/mutability relation well, but it uses the terms "variable" and "value" with different meanings than most programmers would use. What the article calls "value" I would call "memory location" (maybe one could even call it "variable"); and what it calls "variable" isn't 100% accurate but I guess it works to keep the explanation simple.
Have to disagree on this, these are very common words with normal meanings, from the Assignment page on Wikipedia:
> Assignments typically allow a *variable* to hold different *values* at different times during its life-span and scope
https://en.wikipedia.org/wiki/Assignment_(computer_science)
Unless there's something I'm missing, this is exactly how Matt is using those words.
Models where the value `1` in `let x = 1` gets a memory location - they unnecessarily mix in details about where the value is stored. In most cases, the value is not stored anywhere, neither stack nor heap etc, that is just a value and the compiler and compiler settings determine what happens next. A common case is that it's constant folded into some operation, so the `1` then doesn't have any relationship to memory at all.
I think the terms used are typical for Rust. Doesn't each language have its own terms? The C standard's object is not the same as Python's object and so on.
Value is OK.
I don't see what's wrong with variable, it's not like Rust does anything special that warrants a different term.
match value {
n @ 0..8 => println!("{n}"),
_ => {},
}
It lets you bind and use the specific value within a matched range.
I don't think I ever used it though, I tend to write something like `n if n<8 => {...}` insteadThe "value" and "variable" naming is unambiguous though. "Variable" might be problematic for someone that conflates the concepts of reference and value - but that's an issue that should be solved far earlier than ownership.