Programming Elixir Chapter 17 Notes

OTP: Servers

Dave discusses an alternate component-based approach to writing GenServers. This consists of modules in three files:

  • A public API to hide the GenServer complexity.
  • The GenServer interface.
  • Implementatation.

The public API is just a wrapper to the GenServer functions and the GenServer functions are just a wrapper to the implementation. This hides the GenServer call/cast complexity and isolates the implementation.

I like this approach, but think that breaking it into three files is too complex. If the public API is only a wrapper to the GenServer API and the GenServer API is only a wrapper to the implementation, we can easily put them into a single file.

My approach implements the GenServer in two files:

  • Public API which calls the GenServer functions.
  • Implementation
[Read More]

Programming Elixir Chapter 12 Notes

Control Flow

Elixir has an unless keyword, which I don’t recall seeing in any other language I’ve used.

“Elixir exceptions are intended for things that should never happen in normal operation”

Trailing ! in a function name is an Elixir convention indicating failure raises an exception. We’ve already seeing this in the File.open! call in previous exercises.

[Read More]