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
proposal: Go 2: have only one way of declaring variable instead of two #29081
Comments
This proposal needs more background: what is the benefit that would outweigh the cost of updating ~all of the existing Go code? |
Also note that the two forms are not entirely redundant today. package a
type token […]
func Generate() token { […] } package b
func Snoop() {
t := a.Generate() // t has type a.token, but the name 'a.token' cannot be used explicitly within b.
[…]
} The |
Wouldn't that also work with var as well var t = a.Generate() |
I think one of the things I like about Go is that there is typically only one way to write the same program (ie not having built-in streams). This proposal would break nearly every Go program, but it comes at the benefit of there being fewer ways to declare a variable. If this goes through, since |
Duplicate of #377? At least close enough. |
That one seems more concerned about shadowing, and changing the |
I'm also in favor and think most core developers are but I think during Go1 design they actully tried really hard to do just that but they where stuck when it comes to pointer stuff, for example package main
import (
"fmt"
)
func main() {
x := new(int)
var y *int
fmt.Println(x, y)
}
|
We need We want In any case a change like is simply impossible to make at this point. It would break every existing Go program and invalidate all existing Go documentation and examples. There just isn't any benefit here that is worth that cost. |
The |
There're two completely different things: (variable declaration) and (same + assignment at once). Completely useless and breaking change. |
I don't like this proposal too much (since it would, ya know, break nearly every Go program), but saying they are completely different is just not correct. |
We definitely shouldn't change As for local variables, the main issue is that they both have exclusive benefits; I believe we should leave this as one of the quirks of Go, locking it down and throwing away the key as something that we shouldn't change. |
What do you mean by this? |
@urandom Apologies for not being specific. I meant that |
I love the The consistency benefits exist but they are not worth the huge cost. I would go as far as to say I would stop using Go if |
Thanks, but as I said above, we can't make this change to the language at this point. |
Currently there are two ways of declaring a variable in code:
This is inconsistent. Every developer is free to use either style in their code
Proposal: have only one way of declaring variable, either var or :=
The text was updated successfully, but these errors were encountered: