[erlang-questions] OO programming style in Erlang?

Ulf Wiger ulf@REDACTED
Mon Jan 22 14:31:49 CET 2007

Den 2007-01-22 13:52:44 skrev Ladislav Lenart <lenartlad@REDACTED>:

> Ulf Wiger wrote:
>  > As far as possible, try to separate side-effect free code
>  > from that with side-effects. Typically, at least 90% of
>  > your code can be made side-effect free, and it's a good
>  > idea to really isolate the remaining 10%.
>  > [...]
> Does this mean that 90% should be implemented as a
> library functions and the reminding 10% should be
> isolated in a process?

Well, it is highly implementation-specific how you
choose to use processes, but the above probably works
as a rule of thumb. See e.g. Joe Armstrong's PhD
thesis, Making Reliable Systems in the Presence of
Software Errors, esp. chapters 4 and 8.


There are different types of side-effects:
processes, ets tables, process dictionary, mnesia, ...

All have their place, but functions that do not
depend on side-effects are much easier to debug and
reason about, so it's important to structure the
use of side-effects.

It could also be that one first puts data in an
ets table, and later decides that it's better to
have a gen_server or other keeping the data. If
ets accesses are littered all over the place, this
is obviously very difficult to change.

> But one interesting solution using a wrapper
> module comes to my mind now:

You may want to read Richard Carlsson's
Parameterized Modules in Erlang:

The concepts described in the paper have actually been
implemented, albeit flagged as 'experimental'.

Ulf W
Ulf Wiger

More information about the erlang-questions mailing list