forge icon indicating copy to clipboard operation
forge copied to clipboard

Use let to declare variables?

Open olanod opened this issue 7 years ago • 6 comments

I was just wondering if the reason to use var is to be more familiar to Javascript developers? Because JS developers are totally fine with let nowadays is used more than var and that way it also stays closer to rust syntax.

olanod avatar Mar 05 '19 04:03 olanod

let is also permitted as an alias of var, as of a few days ago. In the future, it may gain immutability semantics, so I recommend not writing a lot of code with it. Generally, I'd advise using var where mutability is desired and let where it is not.

zesterer avatar Mar 05 '19 14:03 zesterer

Wouldn't const be preferable over let for this? I prefer constants that are explicit. Because of Rust and JavaScript, let will forever seem like a variable keyword to me.

cedric-h avatar Mar 06 '19 11:03 cedric-h

const has different semantics. const values are intended to be possible to evaluate at compile-time. Examples of this would be type expressions, which need to be evaluated at compile-time for layout information to be calculated.

zesterer avatar Mar 06 '19 12:03 zesterer

Agree with the different semantics of const. The way JS uses this keyword is broken in my opinion, being able to declare an object with const and still modify its properties feels super wrong. Kotlin use of var for things that change and val for immutable values makes sense, could be same here but instead of val use let which makes it feel closer to rust

olanod avatar Mar 06 '19 14:03 olanod

That's roughly what I'm going for, although the systems to get that working aren't (yet) in place.

zesterer avatar Mar 06 '19 15:03 zesterer

Okay, now that I actually understand what you meant I totally agree with the concept. I'm not perfectly happy with the syntax but I can't think of anything better.

cedric-h avatar Mar 06 '19 23:03 cedric-h