The video above was recorded at Elm Conf 2017.
While powerful in its simplicity and important to computation, the boolean can be extremely limiting in Elm applications. In this talk, briefly explore the history of boolean logic in computation and look at how booleans can become misused in Elm. See how booleans obscure the meaning of code, make code harder to maintain, and hinder usability for our teammates and users. By watching this talk, you will learn how to harness union types to write cleaner, clearer code. More importantly, you will learn how to place usability at the forefront of the APIs and UIs you build.
Booleans create problems in four key areas:
- Boolean arguments make function calls confusing, hide important meaning, and create implicit state.
- Functions that return booleans lead to problems like boolean blindness which opens the doors for bugs.
- Spreading application state out among boolean values leads to invalid state and requires more testing to prevent bugs.
- Boolean thinking in UIs can create frustrating user experiences for our users with a simple checkbox. Users have to guess what an unchecked checkbox might do.
You can fix these boolean dilemmas with more explicit data representations:
- Use union type values as meaningful arguments to functions.
- Return union type values from functions to prevent boolean blindness.
- Combine disparate boolean values in application state into one union type like a finite state machine. This makes impossible states impossible.
- Use radio buttons instead of checkboxes to offer explicit options to users. This is similar to using union types to replace booleans in code.
The overarching theme to this talk is to have empathy for our teammates and users by writing clear, self-documenting code and designing intuitive UIs.