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
doc: Effective Go should use sync.WaitGroup, not dummy channel, for Parallelization example #13175
Comments
IMHO the discussed example is way better as it is now than complicating it with
|
The full power of What are the issues that using |
I think effective Go is about using the language effectively,
and as goroutine and channels are built into the language,
we should mention the idiom.
It's true that for the most of the time, you will reach for
sync.WaitGroup rather than constructing synchronization
primitives from channels, but knowing that channels can
construct synchronization primitive is a must for effective
Go programmers, IMHO.
|
For this kind of synchronization(if using a channel), one would normally choose a chan struct{}, to make clear that one is only interested in the synchronization events and not the content transported through the channel. At least this could be changed. |
It's rather easy to understand what's going on when sending Why make stuff less comprehensible? The discussed example is just fine as it is now. It's goal is to explain/illustrate some principle, not to teach how to write the most effective/performant/shortest/you-name-it code possible. |
In teaching I find it's best not to introduce a bunch of new concepts at
once.
You want to lead your student down the path toward enlightenment,
not just take them there and expect them to get it all immediately.
As such, I think the example in Effective Go is good as-is.
|
The example ought to at least close with a mention of |
I think that's reasonable. |
This is a documentation issue.
The section in Effective Go on parallelization shows how to use a channel to count goroutine completions. This seems like bad advice for Go learners, since sync.WaitGroup is a more concise alternative that is expressly designed for this idiom.
The text was updated successfully, but these errors were encountered: