Objects as Actors?
Tony Arcieri, creator of Reia, recently brought up an interesting topic
on unifying actors and objects. Talking about Scala and his disliking
towards Scala's implementation of actors as an additional entity on top
of objects, he says, it would have been a more useful abstraction to
model all objects as actors. Doing it that way would eschew
many of the overlapping functions that both of the object and actor
semantics have implemented today. In Reia, which is supposed to run on
top of BEAM (the Erlang VM), he has decided to make all objects as
actors.
The way I look at it, this is mostly a decision of the
philosophy of the language design. Scala is targetted to be a general
purpose programming language, where concurrency and distribution are
not the central concerns to address as part of the core language
design. The entire actor model has hence been implemented as a library
that integrates seamlessly with the rest of Scala's core
object/functional engineering. This is a design decision which the
language designers did take upfront - hence objects in Scala, by
default, bind to local invocation semantics, that enable it to take
advantage of all the optimizations and efficiencies of being collocated
in the same process.
The actor model was designed primarily to address the concerns of distributed programming. As Jonas Boner recently said on Twitter - "The main benefit of the Actor model is not simpler concurrency but fault-tolerance and reliability".
And for fault tolerance you need to have at least two machines running
your programs. We all know the awesome capabilities of fault tolerance
that the Erlang actor model offers through supervisors, linked actors
and transparent restarts. Hence languages like Erlang, which address
the concerns of concurrency and distribution as part of the
core, have decided to implement actors as their basic building block of
abstractions. This was done with the vision that the Erlang programming
style will be based on simple primitives of process spawning and
message passing, both of which implemented as low overhead primitives
in the virtual machine. The philosophy of Scala is, however, a bit
different. Though still it is not that difficult to implement the Active Object pattern on top of the Scala actors platform.
Erlang
allows you to write programs that will run without any change in a
regular non-distributed Erlang session, on two different Erlang nodes
running on the same computer and as well on Erlang nodes running on two
physically separated computers either in the same LAN or over the
internet. It can do this, because the language designers decided to map
the concurrency model naturally to distributed deployments extending
the actor model beyond VM boundaries.
Another language
Clojure, which also has strong concurrency support decided to go the
Scala way addressing distribution concerns. Distribution is not
something that Rich Hickey decided to hardwire into the core of the
language. Here is what he says about it ..
"In
Erlang the concurrency model is (always) a distributed one and in
Clojure it is not. I have some reservations about unifying the
distributed and non-distributed models [..], and have decided not to do
so in Clojure, but I think Erlang, in doing so, does the right thing in
forcing programmers to work as if the processes are distributed even
when they are not, in order to allow the possibility of transparent
distribution later, e.g. in the failure modes, the messaging system
etc. However, issues related to latency, bandwidth, timeouts,
chattiness, and costs of certain data structures etc remain."
And
finally, on the JVM, there are a host of options that enable
distribution of your programs, which is yet another reason not to go
for language specific solutions. If you are implementing your language
on top of the Erlang VM, it's all but natural to leverage the awesome
power of cross virtual machine distribution capabilities that it
offers. While for JVM, distribution can better be left to specialized
frameworks.
Debasish specializes in leading delivery of enterprise scale solutions for various clients ranging from small ones to Fortune 500 companies. He is the technology evangelist of Anshin Software (http://www.anshinsoft.com) and takes pride in institutionalizing best practices in software design and programming. He loves to program in Java, Ruby, Erlang and Scala and has been trying desperately to get out of the unmanaged world of C++. Debasish is a DZone MVB and is not an employee of DZone and has posted 13 posts at DZone.
- Login or register to post comments
- 3970 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)










Comments
Jonny1985 replied on Mon, 2009/08/10 - 10:09am
mouses replied on Fri, 2009/08/14 - 6:22pm
Very great post, lots of useful information.
Thank for share.
-------------
Bee Directory | EZ Directory | A1A Directory