Monday, December 28, 2009

How to create a program

Right, so I'm back at square one.

I have fibonacci working, again, but this time with Self like objects. So how, now, should I create this fibonacci library inside my VM?

First approach is to create a constructor for the library that, when called, will go through and create everything that is needed for that library. Not too bad when considering such a simple example.

A second way would be to have a special creator function that uses Reflection/Mirrors to create all the objects and their methods. This does a better job of separating the construction logic from the actual application.

The final approach is to use serialization. In this form we have one, common, method for serialising an object graph, and its de-serialising sister. The application that we are creating is built within an IDE of some kind, and then serialised for later use.

I've been trying to think through how this might work in a prototype scenario. I quite like splitting things into a few layers;
  • The application prototype. This contains the definition of all the objects in the application, many of them set up in a prototypical fashion so that users of the program can have a look and see how the thing might be set up. This is essentially immutable.
  • The application instance. (Implying more than one instance...) This extends the prototype and actually does stuff. The prototype should never be touched by the instance (it is shared). This is what is saved when a user wants to save something... using the same serialisation/de-serialisation method.
  • The application transaction scratch space :) where in the application instance does some little bits and pieces on the way to the completion of a computation, but is too transient to bother saving in the instance.
All this requires thinking about the usual serialisation stuff; how do you draw the line around what is to be serialised? How do you link to stuff within that boundary? Outside the boundary?

In this model the application prototype is similar to the class hierarchy side of things in Java etc, but with a little more information about how the whole thing is set up - there's a lot less need for Spring like things as most of the construction has already been done.

I also wonder how/if you might apply purely functional trees (as discussed here) to the application prototype to enable multiple version of the same application running at once, or updates being applied atomically to a currently running app.

No comments:

Post a Comment