On 24 August 2013 20:05, Brad Fitzpatrick <
brad...@golang.org> wrote:
> These are both documented.
>
> reflect.DeepEqual: "An empty slice is not equal to a nil slice."
>
> bytes.Equal: "A nil argument is equivalent to an empty slice."
>
> In the types of places you use each, this is what you almost always want.
I've found that the DeepEqual behaviour is almost never what
I want - it's awkward when testing and you have to depend
on the subtle difference between:
var x []string
for ... {
x = append(x, foo)
}
and
x := []string{}
for ... {
x = append(x, foo)
}
I've been thinking of making a version of reflect.DeepEqual that
compares a nil slice equal to an empty slice, just to get around
that awkwardness.
To be honest, I also wish that a nil slice marshalled as json [] not null
for similar reasons.
Of course, we can't change either of these now...