So, that was a really deep dive into the Equatable
protocol. I bet most of our viewers didn’t expect to get dragged into a abstract mathematical hole in order to understand something that seems to be so simple.
And here is where we try to bring things down to Earth a bit.
Everything we have said up to this point is technically correct, and as you can see there are a lot of weird things that can happen if you start to indiscriminately fudge with the concept of equality. You can very easily write reasonably looking code that gives very unreasonable results, and that completely breaks out intuition when it comes to understanding how code is supposed to work by reading it.
However, even in the standard library there are multiple examples of Equatable
implementations that do not live up to the promise of the documentation of the protocol. And sometimes we need to strike a balance between an idealized mathematical world, and the real, pragmatic world.
So, let’s take a few looks at how these ideas can fall apart in practice, and why we have chosen to live with it.