News for hackers. Stuff that matters.
Re:Go Protobuf: The New Opaque API by tsimionescu on Tuesday December 17, 2024 @10:49AM (#42442321)
Right, forgot that len() works on nil maps, and I was really not aware that reading from a nil map is not an error, that's crazy.

For the nil slice though what I said remains true: a nil slice is the same thing as an empty slice. Of course reading from or writing to its first element panics, given that it doesn't have any elements. The same would have happened if you had initialized it as `var ns []int = make([]int, 0)` or `ns := []int{}`.

Re:Go Protobuf: The New Opaque API by the_gipsy on Tuesday December 17, 2024 @11:03AM (#42442446)
Ah now I get it, yes you're right, they behave the same.

Ironically, just today I read that in the next release they will add some JSON annotation to distinguish nil slices (omitzero): https://tip.golang.org/doc/go1.24