5 ms·
I’m a big fan of ‘var’ and ‘let’ in Swift. Easier to identify mutable vs immutable variables. I believe Carbon uses the same convention? https://github.com/car
by melling 4y ago
I’m a big fan of ‘var’ and ‘let’ in Swift. Easier to identify mutable vs immutable variables. I believe Carbon uses the same convention?
https://github.com/carbon-language/carbon-lang https://github.com/carbon-language/carbon-lang
Helps with quick auto-completion, and someday when I get to dictate code, fewer mistakes.
- nazgulsenpai 4y agoNim also uses 'var' and 'let' for mutability. I like it as well.
- tekknik 4y agoknowing neither of these languages i’d rather it be labeled something more clear as neither one of those screams immutable to me. the immutable variant should use the ‘const’ keyword instead.
- KptMarchewa 4y agoI hope they won't use const. The meaning of it is extremely overloaded in C++.
- donarb 4y agoConst variables are traditionally initialized at compiled time. In Swift, let may be initialized at runtime and then becomes immutable.
- tekknik 4y agothat’s just a choice by the language designer. nothing prohibits initialization at runtime.
- ladberg 4y agoTo me `var` by definition means mutable and `let` sounds like you're laying out a constant in a proof, so I'd say both are pretty clear.
- tekknik 4y agothey both sound exactly the same to me, let sounding like an alias for var. also programs aren’t proofs so we certainly shouldn’t name keywords after them
- lifewallet_dev 4y agoWell Nim also has `const` the difference is that `const` must be evaluated in compile time, but `let` is just to prevent reassignments, more info: https://nim-lang.org/docs/tut1.html#constants https://nim-lang.org/docs/tut1.html#constants which is different than what JavaScript does.
- tekknik 4y ago3 people now saying the same thing. const is not required to be interpreted at compile time, these are choices made by language designers. and read the code with ‘let’ in it like it’s english, does let actually describe constnenss using its english definition? no. i’d argue that any language using ‘let’ for const values is borderline too theoretical. hell, even “define” is better than “let”
- rjh29 4y agoIt's a good convention. Some languages use val and var, which I always thought was bad ergonomics.
- gavinray 4y agoI think JS got it right with "const" and "let"
- mynameisash 4y agoI admittedly only have moderate experience in Scala, which uses `var`/`val` -- but I am glad Rust opted for `let`/`let mut` instead of a single word to make the distinction. It feels much easier to distinguish between mutable and immutable values. I wonder if `var`/`let` is easier because the words aren't as close as `var`/`val`? Or maybe it just gets easier with experience?