Live data from Hacker News

Go package: fanout – make writing parallel code even easier

github.com

21–26 of 26 posts

Re: Go package: fanout – make writing parallel code even easier

#21
Just yesterday I was staring at some of my go code thinking that channels are the "goto" of concurrency. You can make just about anything with them, but to understand code you have to read it all, hold it in your head, and reason about all possible outcomes. In the '60s that's how flow of control was done. As the '70s went by "structured programming" came in and exotic things like while loops, switch statements, and functions that you could only enter at the top (so limiting!) became the norm.

This post proposes a level of abstraction to take a common 10 line idiom and abstract it to a word. I'd much rather read code with the abstraction. (In this case it is clean to read, but there are many complicated patterns in common use involving auxiliary chans for cancellation and timeouts.) Sadly, this is where it collides with the go language designers. Go is anti-abstraction by design. If you don't like that then you descend into interface{} hell and manual runtime type checking, or change languages, or just repeat yourself a lot and pray you get the fiddly bits right each time.

Re: Go package: fanout – make writing parallel code even easier

#22
post #21

Just yesterday I was staring at some of my go code thinking that channels are the "goto" of concurrency. You can make just about anything with them, but to understand code you have to read it all, hold it in your head, and reason about all possible outcomes. In the '60s that's how flow of control was done. As the '70s went by "structured programming" came in and exotic things like while loops, switch statements, and…

Oh, they use abstractions a lot, just not the flow control ones, mainly objects. Like sync.WaitGroup mentioned here is an object and is a completely brain dead choice for this kind of thing. Some form of parallel map() instead would be much easier to understand and to reason about, for example: http://play.golang.org/p/4I-uBJ1Tce

Anyways, I mostly agree, just not generally over abstractions, but more in the context of proper flow control abstractions.

Re: Go package: fanout – make writing parallel code even easier

#23
post #21

Just yesterday I was staring at some of my go code thinking that channels are the "goto" of concurrency. You can make just about anything with them, but to understand code you have to read it all, hold it in your head, and reason about all possible outcomes. In the '60s that's how flow of control was done. As the '70s went by "structured programming" came in and exotic things like while loops, switch statements, and…

Is it easy to use channels for concurrency in UI development. I believe most UI developments use callbacks, such as onClick, handleClick...

Re: Go package: fanout – make writing parallel code even easier

#24
post #7

Oh, hey, it's a generic package that means you lose type safety and saves you from writing roughly 10 lines of code. Buffered channels + goroutines + WaitGroup already allow you to implement this trivially, and because channels are builtin generic, you can do it without the nasty type casts. Really, []interface{} is a terrible type to work with.

Is interface{} similar to type erasure on JVM?

Re: Go package: fanout – make writing parallel code even easier

#25
post #7

Oh, hey, it's a generic package that means you lose type safety and saves you from writing roughly 10 lines of code. Buffered channels + goroutines + WaitGroup already allow you to implement this trivially, and because channels are builtin generic, you can do it without the nasty type casts. Really, []interface{} is a terrible type to work with.

Is interface{} similar to type erasure on JVM?

No, it's most like "Object" in Java.

Re: Go package: fanout – make writing parallel code even easier

#26
post #16

Earlier quoted context omitted.

> Oh, hey, it's a generic package that means you lose type safety and saves you from writing roughly 10 lines of code. Or actually, it's not a generic (as in generics) package, which is why you lose type safety.

> Or actually, it's not a generic (as in generics) package, which is why you lose type safety. Can we please skip just one opportunity to begin this endless flamewar on a HN post about Go? Just one? Please? This topic has been beaten to death and beyond, and is not relevant to TFA at all, as the word "generic" can be used in many contexts, and it's more than clear which context OP meant.

>and is not relevant to TFA at all

How is it not relevant to TFA? This is a speficic example of the problem with not having generics!

Post reply on HN