[erlang-questions] OO programming style in Erlang?
Richard A. O'Keefe
Tue Jan 23 23:29:12 CET 2007
Adam Lindberg <> wrote:
I recall becoming very frustrated with the concept that calling a
method of an object was referred to as sending the object a
message. How can it be sending a message I thought - messages are
things that can only be passed between things with their own parallel
To talk about "message passing" doesn't really make sense for Ada or
Common Lisp (which use generic functions) or C++ or Java, but it *does*
make sense in Smalltalk, where messages do actually
exist as separate objects whenever you look for them and can
be inspected, modified, and forwarded to other objects.
Object subclass: #Message
instanceVariableNames: 'selector args lookupClass'
"I represent a selector and its argument values.
Generally the system does not use instances of Message for efficiency
reasons. However, when a message is not understood by its receiver,
the [system] will make up an instance of me in order to capture the
information involved in an actual message transmission. This instance
is sent to the receiver as the argument of #doesNotUnderstand:."
^receiver perform: selector withArguments: args
When debugging Smalltalk programs, you can see actual Message objects.
I should also point out that Smalltalk has had concurrency since before
Smalltalk-80 and that in CORBA message passing does actually mean passing
real messages over wires (or can mean that).
That attempt to learn that language (possibly C++, I don't recall)
soon ended in distraction.
I think it was Dennis Ritchie (one of the inventors of C) who wrote
"90% of C I use every day; 90% of C++ I don't understand." C++ is very
far from being a typical object-oriented language. Indeed, the latest
additions to the standard C++ library make little or no use of inheritence
but essential use of its Turing-complete template facility.
More information about the erlang-questions