Erlang code reuse model

Mickael Remond mickael.remond@REDACTED
Fri Apr 18 15:05:25 CEST 2003


Hello,

I am to trying to clarify a little bit the code reuse model in
Erlang. There are several approaches that could be emphasized (The
classification could probably be refined):

- Libraries: You can put together the reuseable part of your code in a
  set of Erlang modules.
- The call backs approach: You create an API that can use any module
  that respect a given API defined by a set of functions. The reusable
  parts are put in the API, whereas the specific element of code are
  defined in a module implementing the API.
  This approach has been generalized by the introduction of Erlang
  behaviours.
- Applications: You can decide that what you want to implement is a
  service for other program. You then put the code you want to reuse
  in a separate application. A good example of this approach is
  Mnesia.
- Anonymous function: This approach can be mixed with the libraries
  and the call back approach.
  Anonymous functions can be used to configure a piece of reusable
  code. This approach allow the developer to create reusable code that
  are more flexible than reusable code simply using values as
  parameters.

Now, I found difficult to go further in defining the code reuse model
of Erlang.
I will take an example. Suppose that I want to isolate the piece of
code that are commons in every TCP/IP server written in Erlang. The
code for that is composed of several Erlang behaviours, under a
supervisor.
I have at least two approaches to organise the code reuse:
- Develop a new behaviour, that can be reuse in OTP project that want
  to act as a TCP/IP server.
- Develop an Application that handle the TCP/IP server part and
  delegating the processing of the request to specific ad-hoc modules.

I would do it as an application, as I think it feels strange to have
several processes hidden in a behaviour.

What I would like to do is gather your feeling and your best pratices
to write a synthesis document on Erlang code reuse.  I think this
could be helpfull for Erlang newcomers that are used to other
languages and try to get into the Erlang way of structuring
developments.

So, what do you think ?   :-)

-- 
Mickaël Rémond
http://www.erlang-projects.org/




More information about the erlang-questions mailing list