the OO metaphor
Vlad Dumitrescu
vladdu@REDACTED
Tue Nov 28 23:46:03 CET 2000
The "thread thread" is very interesting, and talking about OO reminded me of
an idea I got... I think it's not a very bad one, so I will share it with
you, to see what you think.
The OO methodology can be easily applied to Erlang, once one gets to ffel
the pulse of the language. There is however one thing that is missing, and
that I think it could be useful. That thing is inheritance.
The natural way for inheritance to be implemented in Erlang isn't the C++
way, but the CLOS way, through some kind of generic functions. A better name
than inheritance might be "shared implementation between modules". An
example might be appropriate.
-module(base).
fun1(blip) -> foo;
fun1(A) -> {empty, A}.
==== and (the syntax is just a proposal)
-module(base_extended).
-extend({base, [fun1]}).
fun1({help}) -> hohoho;
-inherited(). %% need not be always present
fun1(_) -> false.
The meaning would be that the clauses of base:fun1 are imported into the
ones of base_extended:fun1, allowing some of them or all to be overriden.
The gain would be for example that when extending the lists module, one only
needs to write implementations for the functions that are different.
There are problems with the above way of doing it, I know. One might want to
reorder clauses, or to keep only part of the inherited ones... But it is the
general idea that I'd like to discuss.
As someone said earlier (Ulf I think), this creates dependencies between
modules. This isn't always a Good Thing. But on the other hand, when writing
a gen_server, there is a dependency upon the gen_server module... When
trying to implement a module based on another (and that can be used instead
of the other), avoiding to write 50 stub functions that just delegate he job
for the 2 or 3 that need rewriting is kind of a waste. Plus att the compiler
might be able to optimize the calls.
It's almost midnight, and I'm not very sure I managed to explain properly.
I look forward to find out what a wonderful idea you all thin this is :-)
Or alternatively, to find out why it is such a bad idea!
regards,
Vlad
_____________________________________________________________________________________
Get more from the Web. FREE MSN Explorer download : http://explorer.msn.com
More information about the erlang-questions
mailing list