Search⌘ K
AI Features

Keeping the Left Margin Skinny

Explore how to keep the left margin skinny in Elixir projects by using pattern matching instead of control structures. Learn to build single-concept functions that simplify testing and debugging. Understand how to increment records, advance tokens, and reset states in a functional core designed with modular principles.

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 ...