We’re starting a new style of episode here on Point-Free called “Back to basics.”
Most of the time on Point-Free we enjoy diving deep into a topic by devoting multiple episodes to setting up the problem, then solving the problem in a robust way, and then showing how all new fantastic benefits start to pop out when you put in the hard work. And along the way we have explored many advanced topics of the Swift programming language, such as concurrency, value type semantics, existentials, advanced generics, and a lot more.
But often those lessons are tarnished by the fact that they are embedded in a long series of episodes on some other topic, and so many of our viewers may miss out who don’t meticulously watch every single episode.
And so our “Back to basics” episodes are going to focus on one very specific topic related to the Swift programming language, and try uncover everything there is to be known about that topic. And we are kicking things off with a seemingly simple topic, the Equatable
and Hashable
protocols. But it turns out this topic is not so simple after all. They are surprisingly tricky protocols and they have some very specific semantics baked into them that must be upheld, and unfortunately there are a lot of misconceptions in the Swift community on how one can conform types to this protocol. Especially when it comes to reference types.
So, let’s take a moment to familiarize ourselves with the Equatable
protocol, give a deep reading of the documentation for it, and see how things can go wrong if you play fast and loose with the semantics of the protocol.
Let’s dig in.