Erlang / Erlang Advanced Interview questions
What is the difference between a behavior callback module and a plain library module?
A plain library module (like lists or string) exposes stateless functions you
call directly whenever you want — there's no framework driving it, no lifecycle, no expected shape beyond
whatever arguments and return value each function defines on its own.
A behavior callback module instead plugs into a generic, already-running process skeleton (gen_server,
gen_statem, a custom behavior, etc.) that calls your functions at specific points in its own lifecycle
— you don't call init/1 yourself, the behavior's generic engine does, at the moment it
starts a new process. The contract (which functions must exist, with what signatures) is enforced by the
-behaviour/-callback mechanism rather than being purely a documentation convention.
| Plain library module | Behavior callback module |
| You call its functions directly, whenever you choose. | A generic engine calls your functions at defined lifecycle points. |
| No enforced contract beyond documentation. | Enforced by -callback declarations, checked by the compiler/Dialyzer. |
More Related questions...