4 ms·
Having used Kotlin for a while now, I find it really unfortunate that `const` wasn't `val` for the sole reason that it's 5 characters instead of 3. `val` would
by dlbucci 7y ago
Having used Kotlin for a while now, I find it really unfortunate that `const` wasn't `val` for the sole reason that it's 5 characters instead of 3. `val` would have matched nice with `let`, and my multi-variable declaration statements could have had a nice 4-space indentation while still being all aligned.
I know it can be confused with `var`, but no one should ever use that now that `let` exists.
One of these days I'll write my own little language that compiles to TypeScript or something and fix that :)
- melling 7y agoI like that Swift has var and let. Having the first letter be different means less typing with autocompletion. I suppose when I get to use voice recognition for coding, there will also be less confusion.
- eyelidlessness 7y agoGenerally speaking most languages treat `let` as constant/immutable, and the real shame is that JS did not. It's understandable why (they needed a block-scoped `var`), but unfortunate nonetheless.
- hombre_fatal 7y agoA solution I prefer is Rust's where the immutable binding is default "let x" and you opt-in with a modifier to make it mutable "let mut x". It just makes sense for the immutable case to be default by design instead of just by developer habit. "var" vs "val" always were too similar for me.
- bobbylarrybobby 7y agoSwift’s var and let are also good. There is no “default” but “let” is obviously preferred
- bryanrasmussen 7y agoI'm supposing the reason const is const is because it was in the list of reserved words quite early https://www-archive.mozilla.org/js/language/E262-3.pdf https://www-archive.mozilla.org/js/language/E262-3.pdf section 7.5.3 Future Reserved Words - whereas of course val is probably a really common variable name in multitudinous little scripts all over the world and it would basically break the internet if it was used. I would suggest con, but hey that would probably also break a lot of stuff and const wouldn't break anything because being a reserved word you should never have named or been able to name your variable const (probably some JavaScript engine somewhere would have let you though, like early IE/Netscape might have made that mistake)
- dkarl 7y agoMy experience with Scala is that `var` and `val` fortunately look very different in source code. `var` jumps right out at me, perhaps because the shape of the word is so different.
- chrisseaton 7y ago> for the sole reason that it's 5 characters instead of 3 Are you being charged by the character or something?
- setr 7y agoFormatting..!
- the_other_b 7y agoGenuine question (and hoping for your opinion here), why would I use Kotlin over Java? Outside the obvious like developing on Android. I haven't had much exposure to it, but it seems like it has a wider breadth of features and has a quicker development speed?
- rkrishnaan 7y agohttp://steve-yegge.blogspot.com/2017/05/why-kotlin-is-better-than-whatever-dumb.html http://steve-yegge.blogspot.com/2017/05/why-kotlin-is-better...
- mpoteat 7y agoIf you like terse code I recommend APL.
- masswerk 7y agoMind that JavaScript simply reused the set of reserved keywords from Java. This similarity in keywords and syntax is, what made the "Java" part in "JavaScript", while there is actually no deeper relation between the two languages. `const` was available. (However, `let` wasn't in that set, nor in the reserved ECMA extension.)