[erlang-questions] Local and remote sends

Dominic Williams xpdoka@REDACTED
Tue Oct 31 14:30:45 CET 2006


Hi Bob,

> I have a process that usually sends to a CNode, however,
> for testing I use erlang processes running in the same
> session. My sends are of the form:
> {any, From} ! {GatewayPid}
> When I am testing this does not work and gives an argument
> error on running and I have to change it to:
> From ! {GatewayPid}
> Is there some form that will work in both situations?

This is perfect example of what's wrong with naming
processes. It's exactly like having global variables. The
code is dependent on some global ressource which can't
easily be substituted by another.

The solution is for your code NOT TO KNOW who (and in your
case what) it is sending messages to. Pass it the
destination of send operations in some way (extra argument
to each function, extra initialisation argument, parameter
of an abstract module...)

Testing (and reuse) becomes even easier if you go even more
abstract: pass your code a function that it calls instead of
sending messages...

Regards,

Dominic Williams
http://www.dominicwilliams.net

----






More information about the erlang-questions mailing list