Parameterised modules

Sean Hinde sean.hinde@REDACTED
Mon Sep 1 11:58:46 CEST 2003


A few thoughts on the proposal for parameterised modules as presented 
at the Erlang Workshop on Friday.

The two main examples given are nice enough in themselves, but 
comparison with real world apps points out a couple of problems.

The first example is of a generic server, where the server module can 
be parameterised with the name of the callback module and a process 
registered name:

Server = server:new(Name, Mod).

If we look at gen_server however there are two startup functions - one 
with 3 parameters and one with 4 - one which provides a registered name 
and one which doesn't. It is not clear to me that a parameterised 
gen_server could offer both variants (given a fixed number of 
parameters in the module definition), withought imposing on the user 
some convention that if the registered name was say '$undefined' then 
the register step would be explicitly skipped.

The second example is of providing a user defined log function at 
module instantiation. Every time I have wanted to provide for a user 
definable log function I have also wanted to have a built in default 
logger, and provide the caller the option to provide their own if 
desired. I do not see any way to provide a default value for a 
parameter in the proposal for parameterised modules.

So in summary the two weaknesses I see are:

1. There is no way to provide variable numbers of instantiation 
2. There is no way to provide default values for instantiation 

I do not see an easy way to fix these problems, and I would say that it 
is fairly serious that these two potentially very common examples are 
not covered well by the proposal.

I am also quite a bit concerned about the increased potential for 
making spaghetti code - even the likelihood of a server module being 
defined separately from where it is started up will make code 
maintenance more costly.

Thoughts anyone? Any good examples of where this would be amazing? And 
apologies if I have confused the heck out of the 90% of folks on the 
list who were not there on Friday..


More information about the erlang-questions mailing list