Smart variables

SmartVariables is a term introduced in 1998 referring to a design pattern that merges networking and distributed object technology with the goal of reducing complexity by transparently sharing information at the working program variable level.

SmartVariables style programming interfaces emulate simple "network shared memory." The design emphasis is API simplicity for systems needing to exchange information. Sharing and update behaviors do not need to be explicitly programmed; however "callbacks" can be attached that execute when a "named" object's content changes. SmartVariables attach an email-like "name" to each container or list; when the variable changes value, it automatically propagates change events across the network into other running processes working with that data. Applications do not poll for content changes, as events get processed asynchronously &mdash; working program variables simply receive new content.

The concept has some similarities to that of stored procedures and triggers in database systems, where a change to one item can set off other changes in the database.

Programming Basics
This C++ example is from the GPL open-source SmartVariables implementation at SmartVariables.com. Imagine an environment with three networked computers named: Alice, Bob and Charlie. To begin, our program running on “Alice” will function to continuously print out the contents of a remote container object named “greeting@Charlie.” Here is the code for Alice:

Var greeting; greeting.Name( “greeting@Charlie” ); // attach to and subscribe to the remote object while (1) { cout << “greeting=” << greeting << endl; // note that ‘greeting’ can change values here }

Note that Alice’s display code is in a tight-loop, and there is no code that explicitly connects to machine “Charlie” to retrieve the “greeting” object or any changes made to it. Next, we run another program on machine “Bob” that simply changes the value of the remote “greeting@Charlie” object to be the string “Hello, World!.” Here is the code for Bob:

Var greeting = “Hello, World!”; greeting.Name( “greeting@Charlie” ); // modify all copies, everywhere.

Now, when the above program on machine Bob gets executed, it transparently connects to Charlie and modifies the “greeting” object to have its new value: “Hello, World!.” Because SmartVariables containers “know” who have copies of their data, the environment transparently propagates the change to Alice. SmartVariables propagate themselves into process-level code automatically. This means that the program still looping on Alice will now begin printing its new value of “Hello, World!.” The code on Alice appears to be a “tight loop,” with no opportunity for the object to be modified; however, it does change. Modifications to the “greeting@Charlie” object become automatically reflected by Alice’s program output. This behavior is quite amazing to see.