News for hackers. Stuff that matters.
Re:Dave Herman’s contributions to Rust by MrBuddyCasino on Monday May 03, 2021 @05:32AM (#27023111)
Kotlin's version is even better: val & var

Super clear. The "let" version smells a lot of "I have a CompSci PhD".

Re:Dave Herman’s contributions to Rust by wink on Monday May 03, 2021 @05:57AM (#27023240)
No, not at all. I hate var & val because I never can remember which is which (from Scala, which I never really used a lot).

let vs let mut is /clear/ - you can simply not mix them up.

Re:Dave Herman’s contributions to Rust by akvadrako on Monday May 03, 2021 @06:05AM (#27023273)
How is it not clear that var is variable?
Re:Dave Herman’s contributions to Rust by rover0 on Monday May 03, 2021 @10:08AM (#27025268)
I'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.

Re:Dave Herman’s contributions to Rust by leshow on Monday May 03, 2021 @05:49PM (#27031190)
Nitpick: "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.
Re:Dave Herman’s contributions to Rust by mkl on Monday May 03, 2021 @06:29AM (#27023402)
Yes. I think the problem may be with the other one. "val" (and "let") don't seem obviously constant to me.
Re:Dave Herman’s contributions to Rust by MrBuddyCasino on Tuesday May 04, 2021 @08:33AM (#27036876)
var => variable

val => value => is immutable

Of course people are different, but this seems clear as day, assmuning very basic familiarity with functional programming?

Re:Dave Herman’s contributions to Rust by jeltz on Monday May 03, 2021 @07:35AM (#27023799)
Yes, whenever I get confused I recall that var is obviously variable so therefore the other one must be val.
Re:Dave Herman’s contributions to Rust by nicoburns on Monday May 03, 2021 @07:38AM (#27023818)
Let is definitely confusing given that JS has let and const (with let being mutable)
Re:Dave Herman’s contributions to Rust by wink on Monday May 03, 2021 @08:02AM (#27023977)
But 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.
Re:Dave Herman’s contributions to Rust by jodrellblank on Monday May 03, 2021 @04:25PM (#27030201)
C# 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;” ?

Re:Dave Herman’s contributions to Rust by rovolo on Monday May 03, 2021 @02:17PM (#27028708)
"val" is short for "value"
Re:Dave Herman’s contributions to Rust by melling on Monday May 03, 2021 @05:41AM (#27023157)
Practically, I prefer let and var because of autocompletion. Type one letter then tab. Of course, if I could dictate I might prefer something else.

I think of it as being more math like rather than PhD.

Nothing wrong with borrowing from math.

Re:Dave Herman’s contributions to Rust by rocqua on Monday May 03, 2021 @05:56AM (#27023232)
From the perspective of "language designers influencing programmers", the difficulty of auto-completing to `let mut` could be seen as something positive.
Re:Dave Herman’s contributions to Rust by BiteCode_dev on Monday May 03, 2021 @06:45AM (#27023487)
A good IDE will let you type "mu", and autocomplete with "let mu", cycling on tab will give you more options.
Re:Dave Herman’s contributions to Rust by mjw1007 on Monday May 03, 2021 @06:52AM (#27023523)
It's interesting if "let" nowadays has mostly 'academic' connotations.

30 years ago I think it would have reminded people more of BASIC or Fortran than (say) Scheme.

Re:Dave Herman’s contributions to Rust by Macha on Monday May 03, 2021 @07:07AM (#27023612)
I think this would have been more true 10 years ago when Haskell and Lisp were the most likely place for people to have encountered "let".

Now? It's in Javascript in its ES6 evolution and related languages, Swift, Rust, and probably other "newer" languages I'm not aware of. Scala had it ten years ago also, but is more mainstream than it was then.

Re:Dave Herman’s contributions to Rust by Ar-Curunir on Monday May 03, 2021 @12:12PM (#27026897)
The hamming distance between val and var is tiny; easy to miss in a code review.
Re:Dave Herman’s contributions to Rust by MrBuddyCasino on Tuesday May 04, 2021 @08:32AM (#27036864)
When assigning to val more than once: in a statically checked language the compiler will complain, and devs default to 'val' anyway. In a dynamic language you'd quickly get a runtime error.

Using 'var' instead of 'val' where possible: the compiler/linter will tell you this.

Or do you mean something else?