Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

val and var #12

Closed
WhiteBlackGoose opened this issue Feb 2, 2022 · 3 comments
Closed

val and var #12

WhiteBlackGoose opened this issue Feb 2, 2022 · 3 comments
Labels
Design document This one came out from an idea but considers many cases and tries to prove the usabity Syntax This issue is about syntax
Milestone

Comments

@WhiteBlackGoose
Copy link
Member

WhiteBlackGoose commented Feb 2, 2022

About val

val allows to make a readonly field/variable/property. Similar to what Kotlin has. It does not guarantee the structure being readonly, but the value itself is. Syntax:

val a = ...

About var

var is identical to C#'s var. It is normally highlighted by the editor.

Declaration:

var a = ...

Explicit type

Define it after :

var a : string = ...
val a : string = ...

Unresolved

Should we make reassignment more explicit, like this:

a <- a + 1

or more "usual", like this:

a += 1
@WhiteBlackGoose WhiteBlackGoose added Design document This one came out from an idea but considers many cases and tries to prove the usabity Syntax This issue is about syntax labels Feb 2, 2022
@LPeter1997
Copy link
Member

LPeter1997 commented Feb 2, 2022

var and val

Mutable and immutable variable declarations should definitely be differentiated.

If we agree on issue #7, we should definitely take some inspiration from Rust in this case. Having var and val makes it way too easy to just get var into muscle memory and use it all the time. Having an explicit mutability modifier could really benefit here (mut var?).

Reassignment

As much as I don't like to rely on heritage behavior, I think the classic =, += and friends are well-established enough to keep them. Things like <- are really annoying to type out on some keyboard layouts and providing sensible compound versions would be harder.

@WhiteBlackGoose
Copy link
Member Author

WhiteBlackGoose commented Feb 2, 2022

Having var and val makes it way too easy to just get var into muscle memory and use it all the time.

This is not the impression I got workign in Kotlin tbh. I write val without even considering otherwise unless I really need var. And the compiler and the IDE will definitely let you know if you misused var.

@yamin8000
Copy link

I agree with var as variable and val as value, it's just simple and concise. Other languages let or mut just adds more confusion.

@WhiteBlackGoose WhiteBlackGoose added this to the 0.2 milestone Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Design document This one came out from an idea but considers many cases and tries to prove the usabity Syntax This issue is about syntax
Projects
None yet
Development

No branches or pull requests

3 participants