How to Use Mutual Exclusivity in Programming

Learn this common pattern and prosper

Jonathan Hsu
Code 85

--

Framing a problem is the first step to solving. At first, it may appear every problem is unique, but the reality is that common patterns emerge through repetition. Identifying these patterns is critical to quickly and accurately prescribing the answer.

One such common pattern is called mutual exclusivity. You may have heard the phrase “those are not mutually exclusive”. Do you know what that actually means?

In this tutorial, we’ll define mutual exclusivity, examine a real-world example, briefly explain its roots in logic, and finally introduce how it applies to programming.

What is Mutual Exclusivity?

When two items are mutually exclusive, that means that they cannot coexist. Going back to the phrase “those are not mutually exclusive”, this means that the items/states of being are able to coexist.

Liking sports and programming are not mutually exclusive; it’s perfectly valid that one would like both.

A Real-World Example

Expanding on the definition of mutual exclusivity, lets look at a more robust real-world example. Have you ever seen a question that asks “choose all that apply” but also has a…

--

--