News for hackers. Stuff that matters.
Re:Updating the Go Memory Model by laumars on Monday July 12, 2021 @12:09PM (#27811738)
It took me a loooong time to fully wrap my head around channels. They’re definitely not explicit and full of subtle yet devastating bugs when used inappropriately (which is all to easy to do too). Some of the boilerplate code around using them is just ugly too.

That said, there are occasions when channels have proven invaluable. I think the real issue is they were branded as a killer feature but in reality their usefulness is a little more niche than a mutex.

Re:Updating the Go Memory Model by elithrar on Monday July 12, 2021 @12:16PM (#27811815)
> I think the real issue is they were branded as a killer feature but in reality their usefulness is a little more niche than a mutex.

Agree - and many people are surprised to learn both: a) how fast mutex ops are in practice, and b) how channels use mutexes under the covers.

Re:Updating the Go Memory Model by tapirl on Monday July 12, 2021 @07:00PM (#27816095)
Mutexes and channels really overlap in some functionalities, but not totally overlap, okay?
Re:Updating the Go Memory Model by HeyImAlex on Monday July 12, 2021 @12:33PM (#27812043)
They could have been a much more powerful primitive, but not having generics means tons of boilerplate; all basic channel patterns involve a lot of copy pasting.
Re:Updating the Go Memory Model by jasonwatkinspdx on Monday July 12, 2021 @03:59PM (#27814379)
Once generics have been out there for a while and the patterns of use in the community are clear/stable, I think there's a decent chance they'll revisit channels to help clean that up. It certainly is frustrating.
Re:Updating the Go Memory Model by fpoling on Monday July 12, 2021 @06:11PM (#27815715)
Channels in Go lack priority support which made them unusable to express some patterns.

Fortunately one can code a replacement for channels in Go using mutexes and semaphores. And that exercise in turn allows one to see that in many cases the channels are just a bad model. Things like having a single polymorphic priority message queue per go routine suits many cases better than dealing with multiple channels.

And this has been known since nineties if not eighties when Ada had to add mutexes after early designs based purely on channels. So it is puzzling why Go made channels such a central feature when the priority queue just works judging by Erlang or many successful C/C++ libraries.

Re:Updating the Go Memory Model by chakkepolja on Monday July 12, 2021 @12:24PM (#27811916)
Correct me if I am wrong, isn't a channel basically same as blocking queues in Java? I know go but not much advanced.
Re:Updating the Go Memory Model by eitland on Monday July 12, 2021 @12:52PM (#27812297)
Seems like there are a few differences but nothing I personally would leave normal indexing, kind of working generics, Maven and a choice of 3 world class IDEs behind for: https://stackoverflow.com/questions/10690403/go-channel-vs-j...

To each their own though. I hear a lot of people prefer it.

Re:Updating the Go Memory Model by boyter on Monday July 12, 2021 @08:51PM (#27816704)
More or less, but with the ability to "poison" them by closing which causes downstream go-routines to exit. You can do the same thing in java by checking for a poison object and then terminate your loop.

The close is built into the language itself which is useful, along with the other built in language functionality. I wrote about it here, with an example of how to do it https://boyter.org/posts/file-read-challange/

Re:Updating the Go Memory Model by chakkepolja on Monday July 12, 2021 @10:24PM (#27817105)
Thanks!
Re:Updating the Go Memory Model by clipradiowallet on Monday July 12, 2021 @04:50PM (#27814956)
I don't code Java, but I have the same sentiment about channels in golang to queue's in python.
Re:Updating the Go Memory Model by slaymaker1907 on Monday July 12, 2021 @04:21PM (#27814624)
The killer feature over a mutex, in my opinion, is that mutexes encourage sharing by default which is terrible for both program correctness and performance.
Re:Updating the Go Memory Model by laumars on Monday July 12, 2021 @04:54PM (#27814997)
That depends massively on the kind of problems you’re trying to solve. I’ve written some software where channels were the right tool, and others where mutexes were the correct choice.
Re:Updating the Go Memory Model by catlifeonmars on Tuesday July 13, 2021 @10:38AM (#27821505)
This is a shame, because if done correctly, “share memory by communicating” eliminates a whole class of bugs.

I agree that the ergonomics of Go channels leave a lot to be desired. Also, channels are still a primitive: you still need to build abstractions to do anything nontrivially useful with them. I think something like a good coroutine abstraction, or thread nursery abstraction would be ideal.

Re:Updating the Go Memory Model by tapirl on Monday July 12, 2021 @06:58PM (#27816070)
You should not blame Go channels for your inexperience of using them.