Re:nil, Nil, NULL, NSNull
by jerf on Monday January 07, 2013 @02:52PM
(#5022828)
That is incorrect. Certain types can be nil, and those types have a zero value of nil, but nil is not equal to the zero value for all types. You don't have a "empty array" there, you have an uninitialized slice, with no corresponding array at all, empty or otherwise. Uninitialized slices are nil, but that is not generally true, only for the specified types. If you initialize it, even to an actual "0 array" (as close as we can get), it ceases to be nil. See http://golang.org/ref/spec#The_zero_value , and w.r.t. the tour code, switch it to:
(Oh, and for those that don't know, on the other end of that tour link is the live Go tutorial, which allows you to run arbitrary Go code in your browser. You can fiddle with this live, with no installation of Go.)
[ Parent
| on HN ]
There are no comments on this comment yet.