[erlang-questions] OO programming style in Erlang?

Sean Hinde <>
Tue Jan 23 20:44:11 CET 2007


On 23 Jan 2007, at 19:11, Ladislav Lenart wrote:

> And this I guess is the part I have a psychological problem with.
> I am used to an idiom where data are hidden behind an interface
> that operates on them. This decouples user of the module from
> having to deal with internals of that module. But as you described
> it, data are exposed in Erlang. So each time you want to change the
> representation (add something because of one new function), you have
> to revisit many of the existing functions that operate on that
> representation. This seems more than a few changes to me...

Not so bad. If you use records then it is just a recompile (I  
recommend incororating edep into your build process). If you  
seriously change the meaning of the data then I see no difference -  
all users have to take care of the new meaning anyway.

If you are simply changing the representation without changing the  
meaning then you must have a lot of spare time on your hands :-)

Presumably writing your system in erlang means you have some  
concurrency. One guideline would be to design the boundaries between  
processes so that the interfaces are simple or regular, and reserve  
the complex stuff to be inside the process and hence limited to a few  
modules.

I guess in that sense there is some similarity to Smalltalk, except  
that the granularity is larger and the decision criteria for the  
boundaries is different.

Also fair to say that in some systems I have worked on it has become  
extremely tedious and error prone to change the representation of  
pervasive data structures. At such times I have even wished for some  
static typing help :-)

Of course there is nothing stopping you from building your own dict  
style modules for common data structures in your app - the erlang way  
for this (as well described by Uffe) is to pass the whole old data  
structure into the function, and get back a new one modified - pure  
functions without  side effects.

Sean






More information about the erlang-questions mailing list