News for hackers. Stuff that matters.
Re:Having fun with Go's nil, interfaces and errors by cakoose on Saturday September 17, 2016 @03:31PM (#12522019)
Sometimes you try and make one feature work a certain way and that decision has unintended consequences. Most languages have surprises like this.

In this case, it's an implicit conversion from "nil" to the "nil value" of a given type. This is convenient in many cases, but causes confusion in other cases.

Re:Having fun with Go's nil, interfaces and errors by kjksf on Saturday September 17, 2016 @04:58PM (#12522424)
In Go, it's called "zero value", not "nil value".

It's also not an implicit conversion from nil to something. Nil isn't a value the way 0 is a value of an integer or "foo" is a value of string.

Per Go spec (https://golang.org/ref/spec) nil is "predeclared identifier which has no type". That implies it doesn't have a value and therefore cannot be converted to a value.

Nil is zero value of pointer types (which in practice end up being a pointer whose value interpreted as integer is 0) and also a zero value of interface type (which is interface without a type and without a value) and a few other types.

Re:Having fun with Go's nil, interfaces and errors by catnaroek on Saturday September 17, 2016 @04:47PM (#12522370)
> In this case, it's an implicit conversion from "nil" to the "nil value" of a given type.

Upvoted because of this, because it clarified my earlier confusion. That being said, I don't really agree with the rest.