Hacker News new | ask | show | jobs
by ikiris 1249 days ago
don't do that?

this kind of thing is why deepcompare exists to begin with

2 comments

It seems unrealistic to assume that everyone on a reasonably sized team knows all of the subtle edge cases to avoid and never makes mistakes
I can nag everyone to use reflect.DeepEqual and live with some false negatives, but maps always use k1 == k2.
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.