-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: make the keyword 'map' optional #41244
Comments
Duplicate of #36508 |
@changkun Not exactly, #36508 is to remove the keyword 'map', my proposal is to make it optional. The main argument to refuse #36508 is that this change is not backward compatible. But if the word 'map' becomes optional this will not break any code. But thank you for pointing #36508, which I didn't know. |
But... it's not? There's an obvious ambiguity with the array declaration syntax. This has also been pointed out in #36508. And that's a big price to pay for the privilege of saving literally 3 characters when declaring a map type. |
@ALTree it depends about what ambiguity we are talking. From the point of view of the compiler there is no one : In any case we can use the optional It looks to me strange to want to keep |
With the introduction of custom generics, I would like to see converting the |
Right now, the language is unambiguous when it comes to maps and arrays without type information. That is what the original thread was about. Requiring type information to tell if a type expression is a map seems like a step in the wrong direction.
Both of those changes would be language changes. Please note that you should fill https://github.com/golang/proposal/blob/master/go2-language-changes.md when proposing a language change. |
This seems to increase reader confusion for minimal benefit. Separately, making |
@kpym does func f() [string]int return a map or an array? |
@davecheney The only ambiguous case (for the reader, not for the compiler) that I have seen so far is I'm very interested if somebody can show me another ambiguous case. |
@ianlancetaylor Is var a string
a = "initial" or var a = "initial" or a := "initial" We can also discuss how mandatory is |
https://play.golang.org/p/1p6DNYj0Lbs Without the map[ prefix the go parser would need a symbol table to know if |
It looks like the compiler already knows that https://play.golang.org/p/ES0oBp3F3li So in this particular case where |
@kpym as said before, then you're relying on the type system to realise if a type expression is a map or an array. That's a significant step backwards. Also, a reminder that there's a form you should fill for language changes, which I linked above. |
The ambiguity is for the parser. |
There are other ways to write variable declarations, but It's true that there are multiple ways to declare variables. There are reasons for that. As I said, we only add a second way if there is a clear benefit. I'm not seeing the benefit here. |
For language change proposals, please fill out the template at https://go.googlesource.com/proposal/+/refs/heads/master/go2-language-changes.md . When you are done, please reply to the issue with Thanks! |
It seems that no one agrees with me on this subject. |
If you're not going to fill the template linked above, I do agree that we should close this. |
I was not able to figure out some case where removing the 'map' keyword create ambiguity.
Go do not have 'slice' keyword to define slices, why we need 'map' ?
or even
looks to me without ambiguity.
IMO, the syntax without 'map' looks :
[]int
vs[string]int
vsmap[string]int
).The text was updated successfully, but these errors were encountered: