guidance

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Wed Apr 28 12:53:18 CEST 2004


On April 28, 2004, at 10:49, Dustin Sallings wrote:

> My concern is that I'm trying to do FP but it feels like OO 
> with all the message sending and stuff.
> 
> 	I'm not complaining, it is just a bit surprising.

As others have pointed out, it's quite normal for Erlang programs
to display OO-like characteristics. The module system is another 
area where one can find OO tendencies (without inheritance, that is.)

Example:
dict:new() -> Dict
dict:append(Key, Value, Dict1) -> Dict2
...

(The functional part is that the return value is the updated object.
Using a process, one can - as you have seen - circumvent this.)

Then there is of course the polymorphism achieved through
pattern matching in function clauses, and encapsulation through
the use of closures ("funs"):


mnesia:activity(ActivityType, Closure) -> Result.

where ActivityType := transaction | dirty | ets | ..., and 
Closure is an opaque function object.
'mnesia' is the class, if you will, and 'activity' is the 
polymorphic method.


It's perfectly Ok for Erlang programs to feel like OO, as long 
as they also feel like Erlang.  (:


> The erlang way is starting to feel a little like OO and I'm trying to 
> figure out if that's because I do too much OO or it's a 
> secret that you don't tell people when they're learning erlang.

I think the proper way to approach the subject is to first learn
Erlang, and then discover which OO principles can be (and in fact are)
used in Erlang programs. People who approach Erlang with an 
"everything is an object" mindset have a tendency to waste lots of 
time trying to "fix" Erlang by adding inheritance.

/Uffe



More information about the erlang-questions mailing list