Moment := micro + component

Is there anything like “pure OO runtime environment” ? Since “primordial” OO, we have come to understanding that OO runtime should consists (basically) of objects which are sending messages to each other. And nothing else.

The small side issue is that since then, no one has yet come up with the consistent and universal definition of these. Therefore we still have no general consensus on what is the “object” and what is the “message”. Also we have realised there are infinite number of infinite levels on which this “fuzzy” architecture indeed exists and repeats itself. Like a Mandelbrot pattern of the software universe. Objects and messages, object and messages, objects and messages … ad infinitum.

Back to reality. I can actually not remember seeing anywhere , “clean cut” run time environment, which implements this simple architecture ? Run-time environment where there are only objects and messages. Something like this :

[sourcecode lang=”javascript”] // there is only one way of creating objects
// "name" is the only mandatory key-value
var person = create_object(‘{ "name" : "person", "ssid" : "jzxc.0234" }’) ;
// each object has only one method : answer ( message, callback )
// that takes the message and a callback for asynchronously returning the result
person.answer("what is your name?", callback ) ;
// callback has only one argument : data
function callback ( data ) {
// here we use the data returned
// perhaps calling another object
var page = create_object("page") ;
page.answer( "alert " + data ) ;
// no callback used, it is an optional argument
}
[/sourcecode]

No methods, no properties. Just messages. And a micro mechanism for sending (aka “taking”) a message. In case you thought of SmallTalk run-time, this is much cleaner than that obviously.

Now, should we try to “dig deeper” perhaps ? I can explain that I will implement this in a JavaScript (as YAL : Yet Another Language ). “Grammar” sketch is this :

[sourcecode lang=”javascript”] // run time definition
message := JSON string
callback := javascript function with a single argument
public object := an object with two methods "answer" and "remember"
method answer := "answer" ( message, callback )
method remember := "remember" ( JSON string, javascript object )
[/sourcecode]

Method remember is used for object implementations. This is an environment which on the global level uses the above defined abstractions. Bellow that (in closures) there is standard javascript. There is no communication between closures, besides through a mechanism described. Now, let us see how do we define implementations.

[sourcecode lang=”javascript”] // all normal javascript is hidden in closures
( function () {
var myObject = {} ;
//
object.remember ( "my_object", myObject ) ;
// after this myObject is available in runtime environment as named
})() ;
[/sourcecode]

The implementation are made of normal , but all “hidden” javascript and this “message based” global-space environment. Calls to “take” method are only asynchronous. There are no synchronous calls.

It seems this way , I have actually described an component (global-space) layer inside javascript programs. Which is (remember Mandelbrot) the same architectural pattern, found one level above, and level above it, in the SOA universe. So why do not I redefine all of this as an micro-component JavaScript mechanism ?

And since “micro-component” is not catchy enough I shall call my micro component : “moment”. (perhaps: micro + component = moment ? ). Ok here we go:
Of course I shall use javascript code to define this. ( this should make it more clear ). I shall also use this opportunity to change “answer” to “react”. Which is a name , that I think better describes the purpose of the function: ask object to “re-act” on the message you are sending.

[sourcecode lang=”javascript”] // micro + component = moment
// moment constructor requires its name and an object which is moment going to use to "answer"
Moment = function ( name, object) {
// the only method of the Moment public interface
react : function ( json_string, callback ) {
// json structure depends on the contract after which above object argument is implemented
// callback is optional
// this method is asynchronous
}
}
// global mechanism interface
// used to re-create previously remembered methods
Moment.recreate = function ( json_string ) { /* implementation /} ;
// remember a new Moment
Moment.remember = function ( json_string, object ) {/
implementation */} ;
[/sourcecode]

Important to understand is that in here, standard JavaScript code is not allowed in the global space. Only inside callbacks, and inside closures. In this scenario global-space should contain only moments exchanging messages. And callbacks inside which application logic gets implemented with standard code.

[sourcecode lang=”javascript”] // Moment mechanism usage
// First the implementation in a "normal" javascript
(function() {
// it is a requirement not to have anything global
var dictionary = {
"set": function(k, v) { return this["" + k] = v; },
"get": function(k) { return this["" + k]; }
};
// now assign it to its Moment, so we can use it
Moment.remember(‘{ "name" : "dictionary"}’, dictionary);
// "name" is mandatory keyval
})();

[/sourcecode]

Remember how we started: searching for a pure “runtime” environment. This prototype is more of a “global-space in javascript applications” but still valid.
It is easy to imagine JavaScript pre-compiler which will enforce these rules and global space Moments.

Work in progress