[erlang-questions] Supervision Tree
Garrett Smith
g@REDACTED
Wed Nov 28 16:21:57 CET 2012
On Wed, Nov 28, 2012 at 4:34 AM, Bengt Kleberg
<bengt.kleberg@REDACTED> wrote:
> Greetings,
>
> First let me mention that I prefer to never mix call back code that runs
> in a special process (in this case the supervision process) with code
> used by other processes. So, start_link/0 is better off in another
> module.
I would disagree with this in general and especially for someone
starting out in Erlang. There might be cases where separating the
client and server implementations into two modules makes sense, but
it's not typical.
There are a couple things I like to do to clarify the two very
distinct layers in a gen_server/service module:
- Provide separate export attributes: one for the client facing API
and another for the process callbacks
- Separate the two types of functions within the module at top and
bottom and denote them with clear comment banners
E.g.
%%% ==============================
%%% Public API
%%% ==============================
...
%%% ==============================
%%% Callbacks
%%% ==============================
...
Certainly this is a matter of usability, so devs should use whatever
works best for a particular case. But it's far more common to see a
single module for this.
Garrett
More information about the erlang-questions
mailing list