If I may attempt a paraphrase: CPU caches stop being a bandage for slow access to RAM and become a valuable first class citizen for each core of the CPU when coupled with the actor model.
Did I understand you correctly? Again, thank you.
381 karma · joined November 2, 2010
If I may attempt a paraphrase: CPU caches stop being a bandage for slow access to RAM and become a valuable first class citizen for each core of the CPU when coupled with the actor model.
Did I understand you correctly? Again, thank you.
An interesting statement that; particularly the part about mutable variables. Mutability implies state, and state seems to be something we, as programmers, often struggle with. Keeping the those state transitions within our mental model seems to be the hard part.
I've been studying Clojure a lot over the past 12 months; it's approach is quite different from the 9-to-5 Java I write. Rich Hickey's notion of disentangling state into value and identity has been so very helpful to me in dealing with the 'problem' of mutability and state transitions in how I write my own code.
Lisp, whatever the dialect, doesn't strike me as the sort of thing that most Java shops (particularly the large corporate variety) are going to swallow, but the ideas of Clojure... Perhaps I need to get out more, but it's the only language I've seen that proudly embraces a deeply functional paradigm without punting on State (or destroying my brain with monads).
I have no deep love for Java, but once Java 8 arrives with lambdas, all I'll really want is a good implementation of persistent data structures.
PS nothing against monads (or Haskell) - I just haven't gotten there in my Perlis journey.
Bottom line: this is cool, how would I build one in my garage with as little wheel-reinvention as possible?
First, the actor model need not imply a separate thread/process for each actor. It's quite possible and in fact common (in Scala's built-in actor library and various Java actor libraries) to run a very large 100k pool of actors in a pool of well under 100 threads. [1] So, the typical notion of having a single UI thread can mesh quite well with actors (just have the UI event loop pump each actor's event loop during idle).
Second, since actors process messages - which are conceptually the same as events - an actor has messages pushed to it by widget(s) upon user interaction. (If this sounds identical to the observer pattern, it's because it is). There's nothing interesting about this step other than the "an event is a message" concept.
Third, and this is the really neat part, actors often involve some concept of blocking on a receive() call - which is an inversion of control from the observer pattern. That is to say an observer/listener is invoked by the UI framework when an event occurs, but an actor, which conceptually has its own message/event loop, can consume events at will. Thus the inversion of control.
So your classic listener looks like this:
// Added via $("#foo").click() or some such...
function onClick(e) {
// do something ... any state must be stored external to this callback
}
But an actor looks like this: // The event loop is started up and pumps indefinitely...
function loop() {
// any state is local
while (running) {
switch (receive()) {
case ....
}
}
}
The event loop in an actor can easily turn into a very tight and explicit state machine. [2] My event loop here is pretty boring, but consider, if after receiving event A, you explicitly block on receive for event B.I posted [2] a while back and there was a decent discussion at http://news.ycombinator.com/item?id=2972581. The section 5 of [2] really describe the idea neatly.
Hope that helps. Please let me know where I left things fuzzy.
1. Actors That Unify Threads and Events - http://lamp.epfl.ch/~phaller/doc/haller07coord.pdf
2. Deprecating The Observer Pattern - http://lamp.epfl.ch/~imaier/pub/DeprecatingObserversTR2010.p...
As a full-time GUI developer (Java/SWT) this is so true it hurts. I would love to see the actor model and/or functional reactive programming become main-stream in this space. The observer pattern alone is insufficient...
It's only useful because Java lacks first class functions and syntax for lambdas. This is the single most irritating thing about Java to me. When this is fixed with the release of 8, the only thing Java will be missing is a really good implementation of persistent data structures a la Clojure.
I'm especially curious how Rich Hickey's approach to state, time, and identity in a functional language fit in?
I would venture that anyone who works in a large corporation is not in this world. Which is a loss; large established corporations have some of the most interesting problem spaces...
This is probably the single most irritating thing to me as a developer. And, the most frustrating part is that this aspect often turns a simple project or a curious dive into a new technology into a knock-down, drag-out brawl with configuration files and dependencies that in the end produces frustration instead of working code.
Will there be services for porting data between platforms?
Edit: to clarify, my use of "just" wasn't meant to be dismissive or diminutive in any way...
How about inverting the tree-map such that the smaller the amount, the greater the portion of the tree-map taken up? You're going to need all of that space anyway for the names of those potentially-nasty additives to be printed in a legible font size...
tl;dr - functional reactive programming is a nice abstraction which addresses many of the flaws in the observer pattern, especially as it is often employed in UIs, and can be implemented quite nicely in Scala.