I propose a guide for (experienced) OOP-devs.
Stuff I think should be covered:
- use composition instead of inheritance
Don’t do what I did, implement inheritance with GenServers
defmodule Base do
use GenServer
def handle_cast(:foo, state), do: ...
def handle_cast(:bar, state), do: ...
end
defmodule Derived do
use GenServer
def handle_cast(:foo, state), do: ...
def handle_cast(:baz, state), do: ...
# !!!
def handle_cast(method, state), do: Base.handle_cast(method, state)
end
-
Understand why immutability is great but comes at a cost - You give up mutability - I often miss this part in FP-introductions, which directly leads to …
-
survival without mutability (understand, ideally implement yourself) map-reduce algorithms. Learn to structure data so that its easy to handle without mutability.
-
learn to love pure functions (testability! understandable code!) which leads to
-
functional patterns - starting with a simple pipe, then with, understand plug and maybe functional core, imperative shell (with proposing this pattern Sasa Juric vastly improved some code of mine here so I love it)