Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A point often missed by new Go programmers is that channels are only for select. In other words, channels are a primitive for handling nondeterminism at the runtime level, not a general purpose queue. If there is no select statement, there is no actual need for a channel.

A well designed interface, not a primitive, is the correct way to express an Object or an Abstract Data Type in Go. Specifically, prefer a Queue or Collection interface over a raw channel. (Unless you need to use select.)

This is our fault though, for putting channels in every beginner example, while never really explaining select properly.



What about range over a channel?


you don't need a range or a channel to iterate over a collection or read a stream to the end.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: