Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between processes/messages in Erlang and objects/messages in Smalltalk?

I'm trying to understand difference between objects/messages in Smalltalk and processes/messages in Erlang. I read the following post on the topic.

As far as I understand, in Smalltalk, everything is an object, and everything has the same "object/message" abstraction - even the number 1 is an object that can only be reached with message passing. Is 1 a process in Erlang/Elixir? Is everything in Erlang a response to message/program paradigm? Can you send a message to a number in Erlang?

Thanks a lot.

like image 438
FullyFunctional Avatar asked Oct 27 '19 09:10

FullyFunctional


People also ask

How are messages passed between processes on the same node?

by what mechanism are they passed between processes running on the same node? Because Erlang processes on the same node are all running within a single native process — the BEAM emulator — message structures are simply copied into the receiver's message queue.

What are messages in Smalltalk?

The definition from SmalltalkLanguage: A message is simply a method call on an object. Smalltalk messages are perfectly synchronous (the caller waits for the callee to return a value), and not terribly different then function/method calls in other languages.


1 Answers

Processes in Erlang and Objects in Smalltalk are indeed the same thing.

At first glance, this is not terribly surprising: Erlang is an Actor Model language. The Actor Model was invented by Carl Hewitt, who based the message-driven evaluation model on Smalltalk's message-driven evaluation model. (Really, Actors and Objects are the same thing; they only differ in some details.) Alan Kay, in turn, was influenced by Carl Hewitt's PLANNER, when he designed Smalltalk.

So, there is a close relationship between Actors and Objects, and therefore, it should not be surprising that Erlang's Processes and Smalltalk's Objects are so similar.

Except for one thing: the designers of Erlang didn't know about the Actor Model!!! They only learned about it later, particularly when Joe Armstrong wrote his PhD Thesis under Seif Haridi (co-author of the definitive book on Programming Paradigms) in the late 1990s.

Joe Armstrong wrote an article in which he strongly advocated against OO (Why OO Sucks), but he later changed his mind when he realized that Erlang is actually very object-oriented. In fact, he even went so far as to claim that Erlang is the only object-oriented language in this interview with Joe Armstrong and Ralph Johnson.

This is an interesting case of what evolutionary biologists would call convergent evolution, i.e. two unrelated species evolving to be similar in response to similar external pressures.

There are still a lot of relationships between Erlang and Smalltalk, though:

Erlang started out as a concurrency extension to Prolog (and even when Erlang became its own separate language, the first implementations were written in Prolog) and is still to this day heavily rooted in Prolog. Prolog is heavily influenced by Carl Hewitt's PLANNER.

Smalltalk was also heavily influenced by what would later become the ARPANet (and even later the Internet); Erlang was designed for networked systems.

However, one of the important differences between Erlang and Smalltalk is that not everything is a Process. 1 is a number, not a process. You can't send a message to a number.

There are multiple "layers" of Erlang:

  • Functional Erlang: a mostly typical, dynamically-typed functional language with some "oddities" inherited from Prolog, e.g. unification.
  • Concurrent Erlang: Functional Erlang + Processes and Messages.
  • Distributed Erlang: Concurrent Erlang + Remote Processes.
  • Fault-Tolerant Erlang: Distributed Erlang + certain Design Patterns codified in the OTP libraries, e.g. supervisor trees and gen_server.

A Fault-Tolerant system written in Erlang/OTP will typically look like something we might recognize as "Object-Oriented". But the insides of those objects will often be implemented in a more functional than object-oriented style.

Interestingly, the "evolutionary pressure" that Erlang was under, in other words, the problem Erlang's designers were trying to solve (reliability, replication, redundancy, …) is the same pressure that led to the evolution of cells. Alan Kay minored in microbiology, and explicitly modeled OO on biological cells. This is another parallel between Erlang and Smalltalk.

I wrote a little bit about this in another answer of mine.

like image 120
Jörg W Mittag Avatar answered Oct 24 '22 05:10

Jörg W Mittag