Skip to main content.

Sunday, July 10, 2011

After a bit of experiment and talk with ppl on the channel, we have approved the idea to introduce a typed prototype programming in Falcon. While blessed dictionaries (or a kind of object we could introduce in this version) are a "random" collection of data and behavior, prototypes a-la-falcon shall be classes whose structure is mutable in runtime. The difference with respect to classes is that prototypes can be altered, and the difference with respect to typeless objects (i.e. blessed dictionaries) is that the structure of data and behavior is shared across all the instances of a prototype.


Prototypes will also be useful to create classes that are are meant to be non-changing, but at runtime.

A declaration shall work like:


ptype = Prototype( "MyProto", base1, base2 )
instance = ptype()


In this scheme, a prototype can be formed by any class or prototype; it can also accept a dictionary that will be used to create properties and methods. Calling a prototype creates an instance; the init method (constructor) can be given to the prototype at its creation or later on, through addMethod() member of the prototype class. Altering a prototype class (by adding or removing a method directly to itself or to some of the base entities, or even by adding or removing base entities in any part of the inheritance tree) will be immediately reflected into all the structure.

This intermediate model between a typeless prototyped object and the Prototype class shall complete our OOP and quasi-OOP model, providing an intermediate choice between going for a static class or a full free-form and typeless object.

Work towards this model is very advanced: We have already the falcon classes complete, and working to complete inheritance resolution. Falcon classes are optimized classes that store only Falcon data, and as such, they can flatten the parentship into an array of methods and properties. Performance of every operation is highly improved with respect to the previous engine.

Then we have the HyperClasses nearly working. HyperClasses are classes that hold pointers to data and classes representing their parents. In short, they are class holding a tree of parent classes, which can be FalconClass, user clases, type-metaclasses or in general any class.

Hyperclasses don't expose any method to alter their structure; the next step is to create the Prototype class, deriving it from the HyperClass that has also the ability to track its changes and propagate them to the child Prototypes. My idea is that of going lazy with that, that is, setting a flag that subclasses will get use to resort themselves when a change is made. However, I still have to deal to some problem and decide how to precisely implement them. The simple way would that of just query all the subclasses for the required methods recursively... that's what other languages with typed prototypes are doing now... but that's not my style :-). I want to see if we can pre-fetch the structure of typed prototypes and change it on need

Notice that changing a typed prototype at runtime seems a rather rare operation, especially if you have the choice of using typeless objects when dynamic behavior is at stake. In my mind, prototypes are mainly meant to have the ability to create classes at runtime, and through functional constructs.

Comments

No comments yet

Add Comment

This item is closed, it's not possible to add new comments to it or to vote on it