News for hackers. Stuff that matters.

Ask HN: Do you recognize this approach to programming?

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?

( 35 comments | 74 points | on HN )
Re:Ask HN: Do you recognize this approach to programming? by CitizenKane on Sunday May 16, 2010 @01:54PM (#1352411)
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).

Re:Ask HN: Do you recognize this approach to programming? by betageek on Sunday May 16, 2010 @02:12PM (#1352461)
Actors are also a large part of Scala - see more details here http://www.scala-lang.org/node/242
Re:Ask HN: Do you recognize this approach to programming? by rdtsc on Sunday May 16, 2010 @01:36PM (#1352381)
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?

Re:Ask HN: Do you recognize this approach to programming? by phugoid on Sunday May 16, 2010 @08:26PM (#1353126)
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.

Re:Ask HN: Do you recognize this approach to programming? by gruseom on Sunday May 16, 2010 @01:18PM (#1352337)
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.

Re:Ask HN: Do you recognize this approach to programming? by phugoid on Sunday May 16, 2010 @01:37PM (#1352383)
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.

Re:Ask HN: Do you recognize this approach to programming? by sparky on Sunday May 16, 2010 @01:51PM (#1352410)
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.
Re:Ask HN: Do you recognize this approach to programming? by Vivtek on Sunday May 16, 2010 @02:14PM (#1352468)
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.
Re:Ask HN: Do you recognize this approach to programming? by jules on Sunday May 16, 2010 @04:49PM (#1352754)
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.
Re:Ask HN: Do you recognize this approach to programming? by kd5bjo on Sunday May 16, 2010 @01:01PM (#1352297)
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.
Re:Ask HN: Do you recognize this approach to programming? by xkenneth86 on Sunday May 16, 2010 @03:07PM (#1352573)
This is not quite the way LabVIEW works.

- Ken

Re:Ask HN: Do you recognize this approach to programming? by vsync on Sunday May 16, 2010 @01:33PM (#1352377)
Re:Ask HN: Do you recognize this approach to programming? by gcv on Sunday May 16, 2010 @03:03PM (#1352561)
(Shameless plug.) Or dgraph: http://github.com/gcv/dgraph
Re:Ask HN: Do you recognize this approach to programming? by phugoid on Sunday May 16, 2010 @03:47PM (#1352641)
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.
Re:Ask HN: Do you recognize this approach to programming? by jemfinch on Sunday May 16, 2010 @03:03PM (#1352560)
I was going to say exactly this.
Re:Ask HN: Do you recognize this approach to programming? by l0stman on Sunday May 16, 2010 @01:24PM (#1352359)
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...
Re:Ask HN: Do you recognize this approach to programming? by sp332 on Sunday May 16, 2010 @01:19PM (#1352339)
Re:Ask HN: Do you recognize this approach to programming? by phugoid on Sunday May 16, 2010 @02:45PM (#1352531)
Yes, that is similar. I hadn't made the connection between this event-based approach and spreadsheets!
Re:Ask HN: Do you recognize this approach to programming? by shawndrost on Sunday May 16, 2010 @03:29PM (#1352609)
No, they just cloned the most widely-used programming language of all -- Excel.
Re:Ask HN: Do you recognize this approach to programming? by ionfish on Sunday May 16, 2010 @01:15PM (#1352329)
Sounds like reactive programming.
Re:Ask HN: Do you recognize this approach to programming? by baddox on Sunday May 16, 2010 @01:06PM (#1352304)
The a = b + c examples looks like http://en.wikipedia.org/wiki/Constraint_programming .
Re:Ask HN: Do you recognize this approach to programming? by gruseom on Sunday May 16, 2010 @01:28PM (#1352366)
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.

Re:Ask HN: Do you recognize this approach to programming? by brianto2010 on Sunday May 16, 2010 @01:25PM (#1352364)
It sounds kinda like binding in JavaFX.

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

Re:Ask HN: Do you recognize this approach to programming? by tel on Sunday May 16, 2010 @04:59PM (#1352776)
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.
Re:Ask HN: Do you recognize this approach to programming? by enum on Sunday May 16, 2010 @01:55PM (#1352414)
Yep, reactive programming. You can do this in JavaScript too: http://www.flapjax-lang.org/
Re:Ask HN: Do you recognize this approach to programming? by dkersten on Sunday May 16, 2010 @03:38PM (#1352621)
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.

Re:Ask HN: Do you recognize this approach to programming? by johnl on Monday May 17, 2010 @10:09PM (#1356172)
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. .
Re:Ask HN: Do you recognize this approach to programming? by maxklein on Sunday May 16, 2010 @01:19PM (#1352343)
Sounds like VHDL
Re:Ask HN: Do you recognize this approach to programming? by sketerpot on Sunday May 16, 2010 @03:12PM (#1352580)
Or Verilog, or any hardware description language that runs events on an event queue while explicitly keeping track of time.
Re:Ask HN: Do you recognize this approach to programming? by mr_seeker on Sunday May 16, 2010 @03:39PM (#1352625)
"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.
Re:Ask HN: Do you recognize this approach to programming? by sketerpot on Sunday May 16, 2010 @09:32PM (#1353220)
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.

Re:Ask HN: Do you recognize this approach to programming? by dkersten on Sunday May 16, 2010 @03:39PM (#1352624)
Or any other dataflow language
Re:Ask HN: Do you recognize this approach to programming? by alanh on Sunday May 16, 2010 @03:06PM (#1352568)
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.
Re:Ask HN: Do you recognize this approach to programming? by leif on Sunday May 16, 2010 @01:14PM (#1352319)
Reminds me of chuck, an audio programming language. http://chuck.cs.princeton.edu/
Re:Ask HN: Do you recognize this approach to programming? by dfreidin on Sunday May 16, 2010 @11:31PM (#1353458)
In my microcontroller classes the professor has referred to this as interrupt driven, as opposed to a polling loop.