tags:

views:

185

answers:

3

Message-passing is a fundamental part of Erlang. Alan Kay has argued that message-passing is a concept more important than objects in his view of object-oriented programming (and he "invented" the term!).

Can Erlang be considered an object-oriented programming language (à la Smalltalk)?

+4  A: 

I think that on the higher level Erlang is object-oriented given that you believe in the original concepts discussed around the term. By this I mean isolation, message passing, polymorphism.

Erlang's processes can hold on to state, perform actions on that state, and they are isolated from other processes since they can't directly effect each other. Since any process can receive any message (and a message can just as easily be delegated to another process who could send a reply to the original sender) I believe it also fulfills polymorphism.

Certainly Erlang on a lower level shows its functional aspects but again I think at the higher level (where you are passing and coordinating messages between processes) Erlang behaves in an object-oriented manner. You just can't get caught up thinking object-orientation is all about classes, inheritance, and method calling (which is different from message passing). That is only how the paradigm has been provided for us in most mainstream languages.

Sean Copenhaver
+9  A: 

Quoting from Wikipedia which quotes from here:

Benjamin Cuire Pierce and some other researchers view as futile any attempt to distill OOP to a minimal set of features.

But looking at their own futile attempt:

  • Dynamic dispatch - if you treat an Erlang process as an object, then yes, it's supported.
  • Encapsulation - if you treat message sending / response as a method call, it's supported.
  • Subtype polymorphism - kind of - if you stretch the definition of behaviours enough, it's supported
  • object inheritance (or delegation) - without any correctness checking, you can substitute one object for another - so let's say it's ok
  • Open recursion - it's supported (send to own process)

So yes - with some smoke and flashes, you could try claiming that Erlang is Object-Oriented. But I could use the same tricks to present C as an OO language, because you can use OO style in it and implement vtables manually.

An answer of any sane person looking at Erlang would likely be "no" Erlang is a functional / message passing oriented language.

Another answer could be "why bother classifying" / "who needs to know"?

viraptor
Mr. X does explicitly talk about OO the way Alan Kay means the term, which is rather less fluffy that what "OO" means today. Clearly C is _not_ OO in the Kay sense, since the language has no notion of message-passing. (And message passing is not method invocation!)
Frank Shearar
+4  A: 

Joe Armstrong has gone on record saying that he thinks that Erlang is "possibly the only object-oriented language" (the context adds "OO in the Alan Kay meaning of the word"). Johnson, in the same interview, points out the same things that Sean Copenhaver says in his answer: in the small, Erlang's a purely functional language; in the large, with processes, it looks exactly like Kay-style object orientation.

Frank Shearar
Ah dang, I completely forgot about that interview. +1 for putting it in there. InfoQ has a couple with Joe Armstrong and it's very interesting to hear him talk about how Erlangers see things.
Sean Copenhaver