-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: multiple value/tuple channels #41148
Comments
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! |
Why wouldn‘t one use a channel of struct instead? |
like I showed in my examples, that requires defining a new type (or typing out an anonymous struct type every time), which can be cumbersome. |
Would you consider yourself a novice, intermediate, or experienced Go programmer? What other languages do you have experience with? Would this change make Go easier or harder to learn, and why? Has this idea, or one like it, been proposed before? If so, how does this proposal differ? Who does this proposal help, and why? What is the proposed change? What would change in the language spec? Please also describe the change informally, as in a class teaching Go. Is this change backward compatible? Breaking the Go 1 compatibility guarantee is a large cost and requires a large benefit. How many tools (such as vet, gopls, gofmt, goimports, etc.) would be affected? What is the compile time cost? What is the run time cost? Can you describe a possible implementation? Do you have a prototype? (This is not required.)
Orthogonality: how does this change interact or overlap with existing features? Is the goal of this change a performance improvement? |
@gopherbot please remove label WaitingForInfo |
As mentioned above, we can just use a struct type. This proposal is syntactic sugar for that. If we're going to add a new tuple type, it should be more consistent than just syntactic sugar for channels. See also #32941. Therefore, this is a likely decline. Leaving open for four weeks for final comments. |
No further comments. |
There have been several requests over time for tuples to be added to go. However, that presents issues with return values. I propose a change with a much smaller scope: multi-value channels:
The reason for this is as follows:
Normally, you don't really need tuples because you can pass around multiple variable and just know that they are associated.
However, in an environment with multiple goroutines, you can't be sure exactly in what order things would happen, and the only way to associate related variables is with a struct type.
Here is the code that inspired me to write this (somewhat incomplete, as I stopped writing it
As you can see, half the code is just defining temporary types to use, where as it would be much less with my proposal.
This problem would also be addressed somewhat by #1285, as it would allow easily using anonymous types in the type signature of the channel.
The text was updated successfully, but these errors were encountered: