Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ask HN: Do you recognize this approach to programming?
74 points by phugoid on May 16, 2010 | hide | past | favorite | 35 comments
A few of the flight simulators I work with use a novel software framework developed inhouse by the manufacturer. I'm curious if any of you can identify something similar.

The convential approach for commercial flight simulators is to use a large shared memory to hold the state of the simulation, and a game loop. Hardware interface signals are fed into that shared memory, and every iteration of the game loop executes software that reads and updates the shared memory.

The novel approach uses no shared memory. When a hardware input signal changes, it raises an "event" consisting of a name and value. The software then raises any other events that depend on this one. They have created a programming language to get the most from this. In that language, say you have:

a = b + c

d = e + f

These two lines will NOT get executed in sequence. They declare relationships between events. When event "b" occurs, the event "a" will be raised and its value depends on b and also the last value of the c event.

It turns out this is really powerful and works well on a distributed system. Did they create something new here?



Many have pointed out a number of implementations of the model you mentioned. This is generally known as the actor model (http://en.wikipedia.org/wiki/Actor_model) in which messages are passed between a number of distinct actors.

This is actually a fantastic model for distributed systems and was implemented in the Erlang programming language for that very purpose. It is the other major model of concurrent computing outside of having some kind of shared memory space (in a true actor model there is no shared mutable data).


Actors are also a large part of Scala - see more details here http://www.scala-lang.org/node/242


You can think of it as dataflow programming where (event,value) tuples are the data.

You can still think of it as the same old shared memory approach, where before the game loop frame gets to "look" at it, some conditional event propagation and generation is performed. In other words if b and c are hardware events. Their values get written to the shared memory. Before the game loop gets to look at the memory, there is a stage where a (an event derived from b and c) is generated. Of course, now you don't have the limitation of a physical piece of shared memory. These events can be distributed across many machines.

> It turns out this is really powerful and works well on a distributed system. Did they create something new here?

I think the power comes from creating a DSL that fits very well in your domain (problem space). It lets you manage a lot events and express relationships between them. Also you seem to have defined an event algebra, where events can be composed. I am not sure how applicable this is to other domains. If your language is abstract and not related to particulars of flight simulators, it might be quite useful...

What is the language called? How proprietary is it?


Strangely enough, they didn't name it anything. They don't really see it as a language, just a logic tool.

From what I've seen, they've included GPL notices in most of their code (something unheard of in this industry). I'm guessing the whole thing is GPL'd, but not published to the Internet.


What makes it work well on a distributed system?

The value of such an approach lives and dies on how well-defined the problem space is. If the domain covered by those events is relatively walled-off and has a very clear protocol for interacting with the rest of the system, that's good. But if it turns out to require lots of special cases, you end up wanting (and probably hacking your way to get at) a general-purpose language and can end up with something more complicated.

Event propagation in response to unpredictable signals from hardware is pretty much what GUI logic consists of. GUI event handling written the obvious way quickly generates into spaghetti under complexity. I've often wondered about a better way, since much of that complexity doesn't feel intrinsic.

I don't know much about games but it seems like a lot of them might be in the sweet spot for this approach, with a lot of complexity that can be expressed using such rules and encapsulated in a way that works nicely with the rest of the program. The devil is in the details, though.


If you use the shared memory approach on a distributed system, each node has a copy of the shared memory, and there's infrastructure for keeping all that memory synchronized. At least that's one way of doing it.

In the event-based approach they implemented, different nodes (PCs) subscribe just to the events they are interested in. It's light-weight, easy to understand, monitor and debug, and it fits the problem well in this case.


In computer architecture terms, the pub/sub system opens the door to more efficient communication in a multiprocessor system, since the data sharing is explicitly known by virtue of the subscriptions; furthermore, a sufficiently intelligent runtime, compiler, or partitioner can optimally (or close) map calculations to processors. How much of a win you get in practice depends on the actual intelligence of the tools and the hardware you're running on. If you're running on a multicore or SMP (e.g., a quad-socket box) hardware cache coherence will do the heavy lifting for you; each processor won't have its own copy of the data, it will be shuttled around to just the processors that need it. On larger-scale systems, a more message-passing approach is indeed the way to go; in fact, it is often the only way to go, since most large-scale machines outside of integrated supercomputers (Cray et al.) don't support shared memory.


I'd call it dataflow. It's also akin to what Excel does when solving a system. In a larger sense, you'd call it declarative (instead of imperative) programming - you're defining the system and an engine figures out how to make the system act like the definition - you're not giving step-by-step instructions.


It's called functional reactive programming. For example you can say:

    box.position = delay(1,mouse.position)
And the box follows the mouse with a 1 second delay. It works by having a data type for time varying values.


That sounds like the software equivalent of a hardware description language, like VHDL or Verilog. I think that's also the model that LabView works on, but they have a graphical editor instead of a textual syntax.


This is not quite the way LabVIEW works.

- Ken



(Shameless plug.) Or dgraph: http://github.com/gcv/dgraph


Great. That's sort of what I was hoping for - to see how the same functionality (no pun intended) could be obtained without brewing a whole new language for it.


I was going to say exactly this.


In SICP, I think they use this approach to simulate digital circuits. http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html...



Yes, that is similar. I hadn't made the connection between this event-based approach and spreadsheets!


No, they just cloned the most widely-used programming language of all -- Excel.


Sounds like reactive programming.


The a = b + c examples looks like http://en.wikipedia.org/wiki/Constraint_programming .


If anyone wants to learn constraint programming, as I needed to do a few months ago, the two best books I found are this one, which is a general introduction:

http://www.amazon.com/Constraint-Processing-Kaufmann-Artific...

... and this one, which is a survey of the literature:

http://www.amazon.com/Constraint-Programming-Foundations-Art...

None of the other books I looked at was even close to as useful as these. Maybe this will save somebody some trouble.


Another name that this goes by is Reactive programming. Some amount of work was done on a haskell reactive programming project called Yampa or Functional Reactive Programming.


It sounds kinda like binding in JavaFX.

http://java.sun.com/javafx/1/tutorials/core/dataBinding/


Yep, reactive programming. You can do this in JavaScript too: http://www.flapjax-lang.org/


Looks like a dataflow approach to me, or perhaps a message passing system (actor model).

The application I'm working on at the moment for my future startup makes heavy use of a similar approach to pipeline computations between components. So far it works very well.


First thing that came to mind was Smalltalk. http://en.wikipedia.org/wiki/Smalltalk. Developed in the 80s but have no idea where it went. .


Sounds like VHDL


Or Verilog, or any hardware description language that runs events on an event queue while explicitly keeping track of time.


"Keeping track of time" is not the right word. What I learned at school is that the VHDL design does all the operations at once, and the software that programs the hardware times everything so that the output of every operation is at the same clockpulse. This means that a=b+c is done at the same clockpulse as d=e+f.


VHDL can model delays for operations, so that any events which they trigger are not triggered until after a delay. This is useful for modeling things like logic gates, which have a propagation delay associated with them.

If you're using VHDL for design automation, and you're going to synthesize it to hardware, then the synthesis program does logic mapping to whatever technology (standard cells, FPGA blocks, etc.) is being used, figures out the logic and interconnect delays, and tries to satisfy the requirement that everything be ready when the clock ticks, while allowing a reasonable clock frequency.

The way that VHDL handles both uses can be a little confusing.


Or any other dataflow language


It reminds me of answer-set programming, which can be used to define states and conditions to toggle states. But this sounds much more expressive.


Reminds me of chuck, an audio programming language. http://chuck.cs.princeton.edu/


In my microcontroller classes the professor has referred to this as interrupt driven, as opposed to a polling loop.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: