Keeping the Left Margin Skinny
Let’s learn how to make use of pattern matching in decision-making.
We'll cover the following
Pattern matching
We can tell a lot about a programmer by scanning code. This is especially true for Elixir. When scanning Elixir, look for the following three properties:
-
Long pipelines
-
Short functions
-
Skinny left margins
We’ve talked about designing for composition and a single level of abstraction. Skinny left margins mean decisions are often made in pattern matches instead of control structures like if
, cond
, and case
. Skinny left margins make single concept functions much more likely, and simplify tests.
For example, when a user answers a question, the response may be correct or incorrect. We’ve built a boolean into our Response
struct to make quick decisions with pattern matching. We’ll fill it in /lib/mastery/core/quiz.ex
:
Get hands-on with 1400+ tech skills courses.