here's a digression:
struct{} is becoming rather common and useful (particularly
as a channel element type). i wonder how people feel about
the possiblity of allowing nil as a struct{} literal - struct{}{} is somewhat
clumsy.
e.g.
struct{}{} == nil (would be true)
var x struct{} = nil (redundant but valid initialiser)
c := make(chan struct{}, 99); c <- nil
-rob
Probably not worth it. I've never spelled struct{}{} myself, to be honest.
> struct{}{} == nil (would be true)
There's no point in comparing a struct{} to another struct{}.
> var x struct{} = nil (redundant but valid initialiser)
That's: var x struct{}
> c := make(chan struct{}, 99); c <- nil
That's the only legitimate case, and it's spelled nicely enough with:
var nothing struct{}
c <- nothing
--
Gustavo Niemeyer
http://niemeyer.net
http://niemeyer.net/plus
http://niemeyer.net/twitter
http://niemeyer.net/blog
-- I'm not absolutely sure of anything.
agreed. but i know that i usually use chan bool rather than
chan struct{} just because it's more convenient to do
x <- true rather than x <- struct{}{}.
the latter better represents a situation when the presence of a value
is significant, not its contents (and for buffered channels and maps,
it's potentially quite a bit more efficient) so i wondered if a little
bit of sugar might make it easier to prefer.
perhaps, as you suggest, i should just get into the habit of writing:
var empty struct{}
(or "nothing", or even "null")
An alternative proposal is to make _ more like /dev/zero than /dev/null:
var x struct{} = _
var y int = _
func f() (bool, string, io.Reader) {
c := make(chan struct{}, 99)
c <- _
return _, _, _
}
However, as Rob said: not now.