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.
Go package: fanout – make writing parallel code even easier
21–26 of 26 posts
Re: Go package: fanout – make writing parallel code even easier
#22Just 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…
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
#23Just 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…
Re: Go package: fanout – make writing parallel code even easier
#24Oh, 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.
Re: Go package: fanout – make writing parallel code even easier
#25Oh, 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
#26Earlier 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.
How is it not relevant to TFA? This is a speficic example of the problem with not having generics!