Pensieri di un lunatico minore

16 August 2007 Erlang

Object-oriented processes

In his dissertation (PDF), Joe Armstrong argues that object-oriented approaches to concurrent programming are difficult to make work. This struck an odd chord with me, because I think it stems from a C++/Java-centric view of object-oriented, but if we go back to the source we have the following bits of definition of the nature of object-orientation:

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I’m not aware of them.

So, messaging is a core of both OOP and what Armstrong calls Concurrency Oriented Programming. In both cases, the concept of messages are used as a strong isolation mechanism to keep one piece from peering into another and fiddling with the internals. In the case of Smalltalk, for example, that “piece” is an Object. In Erlang, it’s a Process.

For local retention and protection, one can easily compare the nature of the hard crunchy protection around a Smalltalk Object, which requires a message to retrieve anything from it1, and an Erlang Process, which is a totally isolated virtual machine. I believe Erlang takes this technique even further than Smalltalk does by effectively creating a virtual machine for each Process. There is nothing, however, that prohibits Smalltalk from doing the same, other than historical artifacts of implementation.

Next, we have the extreme late-binding, which allows for polymorphism and other things in the Smalltalk world. It’s difficult to actually compare these on a strict technical basis, as Erlang generally uses immutable variables and pattern matching, and Smalltalk uses mutable variables as handles to potentially immutable Objects. What I think is in common between the two is the desire to leave flexibility to the programmer and not attempt any form of premature hand-typing.

Honestly, I think that there’s a lot more in common than Joe gives credit for, and the nature of decomposition in Erlang into collaborating processes are similar in spirit to the nature of decomposition in Smalltalk that is done. For example, in implementing a IRC-like server in Erlang in his book Programming Erlang, Joe identifies 5 process types needed to implement it, and while 2 are artifacts of the specific implementation (UI and the Middlemen), 3 aren’t: