News for hackers. Stuff that matters.
Re:Having fun with Go's nil, interfaces and errors by zeeboo on Saturday September 17, 2016 @03:34PM (#12522040)
An interface being equal to nil just because the value it contains is nil would be even more confusing. For example, imagine if you had two interface values, one holding a nil * T and one holding a nil * S. They would both be equal to nil, but not equal to each other, losing transitivity of equality.

Also, sometimes nil is a perfectly valid value of something and can implement interfaces. You can call methods on nil receivers because method calls are just curried function applications over the value. It would be odd if the interface compared equal to nil just because I happened to implement it with a value that's valid with nil.

Re:Having fun with Go's nil, interfaces and errors by katcipis on Saturday September 17, 2016 @06:10PM (#12522766)
I had not thought about transitivity on equality, now it makes even more sense to behave like this. Thanks.
Re:Having fun with Go's nil, interfaces and errors by twic on Saturday September 17, 2016 @08:26PM (#12523262)
Couldn't they also be equal to each other? If equality was defined only in terms of the value and not the vtable (to borrow pcwalton's terms), they would be equal. Are there any problems which would arise from this?
Re:Having fun with Go's nil, interfaces and errors by slrz on Sunday September 18, 2016 @08:46AM (#12525072)
Equality is not necessarily defined for values of different types ("with different vtables", if you will). You can't just compare values of different type and expect a meaningful result.
Re:Having fun with Go's nil, interfaces and errors by twic on Sunday September 18, 2016 @03:18PM (#12526708)
In this case, though, we're talking about interfaces; an interface is a pointer plus this bit we're calling a vtable. Pointers, even to different types, absolutely can be compared for equality, can't they? More specifically, i am pretty sure pointers can be compared to see if they are both nil, which is all that would be needed here.