Sure. I don't have a problem with nil slice and empty slice showing the same, because in all important ways they behave the same - i.e. they have len() of 0, you can append() to them, etc. The only behavioural difference I can think of is if you explicitly test "foo == nil".
However, a slice with len=1 that showed the same as one with len=0, was what confused me :-) On reflection, %v is intentionally ambiguous. There are other examples, e.g. - []string{"a","b"} and []string{"a b"} - []string{"", ""} and []string{" "} On Wednesday, 17 March 2021 at 21:24:46 UTC tapi...@gmail.com wrote: > Printing a nil slice also get the same output []. > > I remembered Rob Pike ever said in an issue thread that this can't be > changed now for compatibility reason. > > On Monday, March 15, 2021 at 8:18:46 AM UTC-4 Brian Candler wrote: > >> I was slightly surprised to discover that the Print() output for an empty >> slice, and a 1-element slice containing the empty string, are the same: >> >> https://play.golang.org/p/btkzgk4LMT9 >> >> It does follow logically from the rules >> <https://golang.org/pkg/fmt/#hdr-Printing>. I guess I need to train >> myself to use %q or %#v. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/52ec470e-65d8-40ac-8b6b-b800da813dbfn%40googlegroups.com.