5 ms·
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
by cakoose 10y ago
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.
- catnaroek 10y ago> 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.
- kjksf 10y agoIn 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 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.