Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do Erlang actors differ from OOP objects?
    text
    copied!<p>Suppose I have an Erlang actor defined like this:</p> <pre><code>counter(Num) -&gt; receive {From, increment} -&gt; From ! {self(), new_value, Num + 1} counter(Num + 1); end. </code></pre> <p>And similarly, I have a Ruby class defined like this:</p> <pre><code>class Counter def initialize(num) @num = num end def increment @num += 1 end end </code></pre> <p>The Erlang code is written in a functional style, using tail recursion to maintain state. However, what is the meaningful impact of this difference? To my naive eyes, the interfaces to these two things seem much the same: You send a message, the state gets updated, and you get back a representation of the new state.</p> <p>Functional programming is so often described as being a totally different paradigm than OOP. But the Erlang actor seems to do exactly what objects are supposed to do: Maintain state, encapsulate, and provide a message-based interface.</p> <p>In other words, when I am passing messages between Erlang actors, how is it different than when I'm passing messages between Ruby objects?</p> <p>I suspect there are bigger consequences to the functional/OOP dichotomy than I'm seeing. Can anyone point them out?</p> <p>Let's put aside the fact that the Erlang actor will be scheduled by the VM and thus may run concurrently with other code. I realize that this is a major difference between the Erlang and Ruby versions, but that's not what I'm getting at. Concurrency is possible in other languages, including Ruby. And while Erlang's concurrency may perform very differently (sometimes better), I'm not really asking about the performance differences.</p> <p>Rather, I'm more interested in the functional-vs-OOP side of the question.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload