4 ms·
How is it not clear that var is variable?
by akvadrako 6y ago
How is it not clear that var is variable?
- mkl 6y agoYes. I think the problem may be with the other one. "val" (and "let") don't seem obviously constant to me.
- jeltz 6y agoYes, whenever I get confused I recall that var is obviously variable so therefore the other one must be val.
- nicoburns 6y agoLet is definitely confusing given that JS has let and const (with let being mutable)
- wink 6y agoBut that is cross-language, which is not ideal but not an internal problem if you work in one code base. (O)Caml also has `let` and is quite a bit older than JS.
- jodrellblank 6y agoC# uses “var” to mean “infer the type”, nothing to do with mutability or not. “Let” feels like some in-joke, coming from a math via lisp heritage of “let k be any number...” to distinguish it in English from the surrounding writing. I have to guess that in early lisp (= k 5) would be an error as k isn’t defined and (k 5) errors because k isn’t a function and (let (k 5)) comes out of need for a binding function and why not “let”. In c-like languages “k=5” is an established binding that both programmers and compilers can deal with. What does “let k=5;” add to Rust over “k=5;” ?
- rovolo 6y ago"val" is short for "value"
- MrBuddyCasino 6y agovar => variable val => value => is immutable Of course people are different, but this seems clear as day, assmuning very basic familiarity with functional programming?
- rover0 6y agoI'm a javascript developer. if mutable is expensive, and should be difficult then "let mut" makes more sense. var looks like a default to me, not a special case that needs care.
- leshow 6y agoNitpick: "expensive" may be the wrong word there, to me that implies some kind of runtime cost. The stated reason for the keyword is that it forces users to think a little bit more about mutability. You may want do this because safe mutability requires exclusive ownership.