-
Notifications
You must be signed in to change notification settings - Fork 1
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
Const Assignments #3
Comments
One way or the other, we should also address the following:
|
I've been thinking of some syntax. Instead of val or var, how about
some syntax mut person Person
person.Name = "" Additionally, Golang's 2 ways of declaring variables with // mut? or const?
person := Person{} Instead I propose not only // goat can guess the type based on what is on the right
mut person = Person{}
const person = Person{}
mut floating = 0.0 // defaults to float64 If the type needs to be explicit then casting can be used: mut floating = float32(0)
mut integer = int64(0) This also has some major side effects (which I find appealing). You are no longer forced to set struct fields after variable declaration when using mut person Person
person.Name = "Abdiel Lopez" Instead the following is possible, and is extremely explicit:
|
I don't see the difference :-(
or
|
yup, it's the same.
Regarding the keywords themselves, I find |
@PaperPrototype just to be clear, most of what you've suggested already exist in go: https://go.dev/play/p/B84ynfexzKk |
In most other use cases, assignment to a variable is a single-time operation. Const assignments allow preventing
accidental shadowing and accidental rewriting of variables, and also allow code authors to convey intent.
Do we want to go with the direction of Kotlin supporting
var
andval
assignments, or we want all assignments to default to const as Rust does withlet
andlet mut
?More context in this blog post section.
The text was updated successfully, but these errors were encountered: