[erlang-questions] Why do we need modules at all?

Dave Challis dsc@REDACTED
Tue May 24 18:05:01 CEST 2011


One thing I'd argue is that modules go some way to indicating the intent 
of functions within (though maybe this can be replaced with good 
function metadata).

Let's say we've got a sets module which happens to implement set data 
structures as lists.

This sets module might define some generally useful list manipulation 
functions, which others want to use.

However, the intent of those functions is to serve the sets module.  If 
the module owner wants to change one of the functions to be faster for 
certain types of list and slower for others, it would make sense to do 
so if it improved performance of the sets module as a whole.

If that function was in a global namespace of functions, it would need 
metadata which indicated something like: "Although this is a general 
list processing function, it is intended to support set data structures, 
and as such may change internally to best serve this set of functions here."

I guess what I'm trying to say is that I can see the need for code 
duplication when you've got:

X, a function intended to do X
Y, a function intended to do Y, which happens to be implemented as X

Though the code for them might look identical, there's the implied 
contract that X will always do X, whereas Y could change at any time.

Modules (or namespaces in other languages) seem to be a reasonable way 
of describing this intent/contract (albeit in vague terms, though most 
modules seem to have an understandable purpose or theme).


-- 
Dave Challis
dsc@REDACTED



More information about the erlang-questions mailing list