Hacker News new | ask | show | jobs
by erik_seaberg 1248 days ago
I can nag everyone to use reflect.DeepEqual and live with some false negatives, but maps always use k1 == k2.
2 comments

This is days later, sorry, but - you can't use an interface as a map key, so this shouldn't apply, right?
https://go.dev/ref/spec#Map_types says that is allowed.

> If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.

There are also significant performance and behavior differences between the two.

They are not inter-changeable, nor can one replace the other.

more specifically, it's really strange to hear of people doing equivalence checks on objects with structure. What are you expecting that comparison to do? I doubt it is doing what you think is happening, and is indeed risky of panics.