gen_tcp:controlling_process

Joakim G. jocke@REDACTED
Sun Mar 2 21:31:06 CET 2003


martin j logan wrote:

 >Jocke,
 >    Out of curiosity what method do you prefer to use when writing
 >something general that you wish a user to be able to extend with
 >specific functionality? I find callback programming to be the simplest
 >technique - at least in Erlang. I would be interested in your
 >opinion/preference - if you have the time and inclination to give it.

I also find callback programming a powerful technique. For example, my
xmlrpc library uses it both in its external API as well as internally,
i.e.

An example of an xmlrpc server implemented via a callback module:
http://www.gleipnir.com/xmlrpc/unpacked/LATEST/examples/fib_server.erl

Internally in the xmlrpc library I use my own callback oriented tcp server:
http://www.gleipnir.com/xmlrpc/unpacked/LATEST/src/tcp_serv.erl

I find the above meaningful.

The problem with the gen_server (and to some extent the supervisor)
module is that its main purpose is to hide central Erlang programming
concepts/constructs, e.g. bang (!), pattern matching on messages in
mailboxes using receive, EXIT signal propagation, tail
recursive-oriented server loops etc.

Sean suggested that I could rewrite my tcp_serv.erl above using
the gen_server. Over my dead body I said. Why? Because it would
provide me with nothing expect boredom, i.e. tracing is available
anyway these days. Software replacement (if I need it) can be
implemented as described here:

http://www.erlang.org/doc/r9b/doc/design_principles/spec_proc.html#7

Personally I think that the recommendation to new Erlang users to use
the gen_server is a disaster. At least when it comes to the growth of
the Erlang user base. They just get the wrong impression on how we
recommend "real" Erlang code to be written.

When I discuss this with Martin B. (one of the people behind OTP)
he usually points at me [like Uncle Sam in the famous president
campaign poster] saying: "So you want us to copy&paste common code in
order to write a new server?". I just have to say yes.

Cheers
/Jocke

PS Sorry for the previous empty message. My son attacked the
   keyboard. :-) DS





More information about the erlang-questions mailing list