5 ms·
Kotlin's version is even better: val & var Super clear. The "let" version smells a lot of "I have a CompSci PhD".
by MrBuddyCasino 6y ago
Kotlin's version is even better: val & var
Super clear. The "let" version smells a lot of "I have a CompSci PhD".
- melling 6y agoPractically, 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.
- rocqua 6y agoFrom the perspective of "language designers influencing programmers", the difficulty of auto-completing to `let mut` could be seen as something positive.
- fuck_google 6y agoObviously you haven't had to maintain code written by mathematicians that prefer to use one letter names for functions and variables among other peculiarities.
- BiteCode_dev 6y agoA good IDE will let you type "mu", and autocomplete with "let mu", cycling on tab will give you more options.
- wink 6y agoNo, 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.
- akvadrako 6y agoHow 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?
- mjw1007 6y agoIt'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.
- Macha 6y agoI 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.
- Ar-Curunir 6y agoThe hamming distance between val and var is tiny; easy to miss in a code review.
- MrBuddyCasino 6y agoWhen 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?