News for hackers. Stuff that matters.
Re:Twelve Go Best Practices by frou_dh on Wednesday July 31, 2013 @01:22PM (#6135328)
Something that doesn't sit right with me is the use of a "channel of bool" when the receiving goroutine doesn't actually care whether true or false is sent. It muddies the API to force the sender to choose one of two values when all that's really wanted is an amorphous signal.

e.g. in http://talks.golang.org/2013/bestpractices.slide#25 , the first case in the select will trip regardless of which value arrives, yet the sender was still made to choose one.

Re:Twelve Go Best Practices by shurcooL on Wednesday July 31, 2013 @01:30PM (#6135405)

  A channel may be closed with the built-in function close; the multi-valued
  assignment form of the receive operator tests whether a channel has been closed. [1]
Given that is available, why is the use of a separate bool quit channel preferred?

[1] http://golang.org/ref/spec#Channel_types

Re:Twelve Go Best Practices by frou_dh on Wednesday July 31, 2013 @02:00PM (#6135616)
In the link, the quit is acknowledged, so one side closing the channel straight off the bat wouldn't allow for that.
Re:Twelve Go Best Practices by dragonwriter on Wednesday July 31, 2013 @01:59PM (#6135608)
A quit channel (that is not receive only) can be used to send back a quit message by a goroutine that only has a receive-only view of the main data channel; close() can't be called on a receive-only channel.
Re:Twelve Go Best Practices by bradfitz on Wednesday July 31, 2013 @01:47PM (#6135525)
Just sending "true" as a signal is a convention, but some people prefer something like http://play.golang.org/p/oXapo7R4RX
Re:Twelve Go Best Practices by frou_dh on Wednesday July 31, 2013 @01:56PM (#6135589)
Cool, I like that. In some ways, it would be nice if there were a friendly alias for struct{} as part of the language, but I suppose it's hard to come up with a good general name for that.
Re:Twelve Go Best Practices by lmm on Wednesday July 31, 2013 @04:59PM (#6136797)
Many languages call it unit or ().
Re:Twelve Go Best Practices by frou_dh on Wednesday July 31, 2013 @05:13PM (#6136880)
Hah, I was just about to edit my comment to mention unit after doing some reading :)
Re:Twelve Go Best Practices by exch on Thursday August 01, 2013 @07:56AM (#6139632)
I'll add that the reason for using `struct{}` over `bool`, is that an empty struct occupies 0 bytes, whereas a boolean occupies 1.