2 ms·
I like Go, but I agree with most said in this article. One nitpick about his comment about sending to closed channels. This is indeed programmer error and SHOU
by breakingcups 11y ago
I like Go, but I agree with most said in this article.
One nitpick about his comment about sending to closed channels. This is indeed programmer error and SHOULD panic, in my opinion. It is clear the author has not read up on the semantics of channels. Channels should only be closed by the sender. If you have multiple senders, how on earth would it be a valid situation for one of these senders to close the channel if the other sender still has data to send? You're going to need some form of synchronisation mechanism for this.
- jusssi 11y agoI believe the idiomatic way to solve multiple writers would be to give each writer it's own channel, and multiplex the output of those to a single channel. The problem is, without generics you need to create a new multiplexer for every type of channel payload. Also, if semantics make life complicated, they should be changed. Since there's already an 'ok' return flag for channel receive, I have hard time understanding why there can't be one for channel send.
- tshannon 11y agoYeah, I've found the simplest way to have multiple writers / readers is a mutex. I was suprised to read that they actually consider removing the sync/atomic packages. It's crucial in my opinion, and would complicate a lot of code if had to be written with channels.