MPF


MC2 and MPF31 Jul 2006 10:49 pm

In my first post on MC2, I said Morphtrons have

the ability to act as components and/or containers

But this deserves more attention as the Composite pattern it represents is one of the most important and pervasive patterns in practice because things in the “real” world are always contained and often contain other things. Back in the mid-1980’s the integrated software environment, Framework, written by Xerox PARC alum Robert Carr demonstrated to me that there were significant benefits to orgainizing everything into a hierarchy of objects. Carr won a Profile In Technical Excellence award in 1985 for Framework. One of the benefits of the Framework approach was that there was no notion of “applications” and the degree of interoperability was astounding and still some 20 years later unsurpassed in a number of respects. MC2 brings back the kind of easy interoperability seen in Framework but missing in Smalltalk. Sure if you are a knowledgeable Smalltalker, you can integrate any two solutions but each one tends to be a special case. Often you end up having to gain a deep understanding of an object just to do something relatively simple with it. In some cases you end up having to analyze whether to refactor the class or create a subclass. With Morphtron you can take existing objects and use them together quickly and easily. As a simple example take two tools that come with Squeak the MPEG movie player and Sound Recorder. Suppose you want objects that have movie players which have their own sound recorders:

myMediaRoom:=Object newNamed: ‘myMediaRoom’.
m_(MPEGMoviePlayerMorph newNamed: ‘Movie Player’) openInWorld.
myMediaRoom addComponent: m.
s:=( RecordingControlsMorph newNamed: ‘Sound Recorder’) openInWorld
m addComponent: s.

m fullName ‘/myMediaRoom/Movie Player’
s fullName ‘/myMediaRoom/Movie Player/Sound Recorder’

No refactoring, no new subclasses, just the capabilities you wanted to create from two classes you didn’t author.

Implementation and MC2 and MPF31 Jul 2006 12:27 am

o_Object new.
o getComponents an OrderedCollection()
o getComponentsNamed: ‘boo’ an OrderedCollection()

o componentName ‘an Object’
o componentName: ‘hello’
o componentName ‘hello’

oc_Object newNamed: ‘world’.
o addComponent: oc.
o getComponents an OrderedCollection(an Object)
oc container componentName ‘hello’
oc fullName ‘/hello/world’

props_Dictionary new.
props at: #mySpecialTrait put: ‘is flexibility - hooray Morphtrons!’
op_Object newNamed: ‘h2′ withProperties: props.
op fetchProperty: #mySpecialTrait ‘is flexibility - hooray Morphtrons!’

op_Object newNamed: ‘h2′ withProperties: {#mySpecialTrait. ‘is flexibility - hooray Morphtrons!’}
op fetchProperty: #mySpecialTrait

Implementation and MC2 and MPF31 Jul 2006 12:18 am

The latest version which includes Morphtron Component & Container support is 0.91.7. You can download it in the Squeak directory. Soon updates will be in changeset and/or Monticello packages.

Implementation and Javascript and Javascript OSA and MOPA and MPF and Mozilla and Web Crossing and Yahoo Widgets(Konfabulator)28 Jul 2006 04:15 am

The following two examples use the same Javascript 1.5 based MOPA.js,

  • Browser based
  • Yahoo Widget Engine(put the MOPA.js file from above into the .kon file)

so the only differences in them have to do with output. I know that earlier versions of Morphtron ran in Javascript OSA and Web Crossing but I haven’t tested this particular file with them - so many platforms, so little time.

MOPA and MPF and Smalltalk and Squeak27 Jul 2006 09:50 am

This simple example included in the beta image is shown below with comments and italicized results.

create a new object
o_Object new. an Object

see if it has a ‘hello world’ property
o fetchProperty: ‘hello world’. nil
put something into the hello world property
o putIntoProperty: {’hello world’. ‘first program’}

fetch the new property
o fetchProperty: ‘hello world’. ‘first program’

when you fetch all of an object’s properties, you get all the methods and instance variables along with the accessories
o fetchProperties a Dictionary(size 453)

this simple object has only one accessory
o fetchAccessories a Dictionary(’hello world’->’first program’ )
o fetchAccessory: ‘hello world’ ‘first program’

There are methods such as hasProperty and hasAccessory and other variants(hasNativeExecutableProperty) that allow you to determine what the properties an object has are.

Dolphin and Implementation and Javascript and MOPA and MPF and Mozilla and Smalltalk and Squeak and Yahoo Widgets(Konfabulator)25 Jul 2006 11:13 pm

A full implementation of Morphtron provides a common, transparent means of providing access to properties by using the native property if it exists. In cases where no native property exists, MOPA methods then use or optionally create an accessory. For example consider this Smalltalk(Squeak and Dolphin) implementation of fetchProperty:

fetchProperty: aSymbol
| property |
property _ self fetchNativeProperty: aSymbol.
property
ifNotNil: [^ property].
^ self fetchAccessory: aSymbol

The details of fetchNativeProperty are left up to the implementor. She can determine what access to native properties will be allowed. The following Smalltalk implementation this:

fetchNativeProperty: aSymbol
| ivarValue |
(self class allInstVarNames includes: aSymbol)
ifTrue: [”aSymbol is an ivar”
(self isPrivateInstVar: aSymbol)
ifFalse: [”aSymbol has not been declared private”
(self class lookupSelector: aSymbol) isNil
ifTrue: [self allowInstanceVariablePropertiesWithoutAccessors
ifTrue: [ivarValue _ Compiler
evaluate: ‘^’ , aSymbol asString
for: self
logged: false]]
ifFalse: [ivarValue _ self perform: aSymbol]]].
^ ivarValue

Now for a prototype-based language such as Javascript, things are simplified because all properties are native:

function fetchProperty(aName) {

/*

Using fetchProperty for accessing properties has a number of different benefits. It is easier for beginner-to-intermediate programmers and allows Morphtron behaviors to be ported between different object environments. It also lets accessories be used transparently as properties. That said, a programmer with sufficient knowledge can still use built-in properties and accessories however she wants. See also fetchAccessory. One interesting use of accessories is for undo.

*/

var theProperty=this[aName];

if(typeof(theProperty)==’undefined’) {

theProperty=this.fetchAccessory(aName);

}

return(theProperty);

}

MOPA and MPF25 Jul 2006 09:45 pm

MOPA provides two capabilities:

  • a uniform, largely syntax neutral means of interfacing with an object’s native properties/fields/instance variables/methods.
  • a uniform, largely syntax neutral means of interfacing with properties unique to a particular instance.These unique instance properties are referred to as accessories.

The “largely syntax neutral” disclaimer is made because Morphtrons could be difficult or even impossible to fully implement in every dynamic OO language. These two capabilites make it possible to write code which can be directly executed by multiple languages across multiple platforms.

There are two executable properties which form the kernel of a Morphtron implementation.

  • fetchProperty
  • putIntoProperty


Continue Reading »

MC2 and MOIST and MOPA and MPF25 Jul 2006 08:39 am

To facilitate implementation and extension, the Morphtron architecture has been modularized into the Morphtron Programming Framework(MPF). The MPF nucleus is known as the Morphtron Object Properties and Accessories(MOPA). A Morphtron object is a collection of named properties. There are two categories of Morphtron properties - Executable and Value, each having two sub-categories Native(as determined by the host language - typically by the class) and Accessory(unique to an instance). MOPA provides the means to create, store and retrieve an object’s properties. Surrounding the Morphtron nucleus is Morphtron Components and Containers(MC2) module which provides objects with the ability to exist in hierarchical relationship to other objects. Another module is called Morphtron Observation Interchange Storage & Transport(MOIST). This is actually a collection of four interrelated sub-modules whose names reflect their function. Each of these modules will be covered in more detail later.

MPF24 Jul 2006 02:42 pm

I had an inspiring conversation(thanks Dwight!) with an old Smalltalker who’s doing PHP 5 and Ruby these days. This short discussion has moved me to shift gears a bit and start pushing the Morphtron Programming Framework(MPF) forward again. In recent times, MPF has been pushed back several notches in order to address the needs of the broader market of non-programmers. Ideally, you want to have all of the lower level infrastructure frozen before doing this but the Morphtron architecture coupled with the time-based message passing of GVScript let’s you reap some benefits of stretching extreme late binding a bit further without changing the underlying language. In addition, I’ve used this framework for so long in multiple languages across different platforms in many applications including production environments and I’m not concerned about the current loose ends. The priorities I\’d been dealing with were:

  • GriotVision pre-built virtual worlds
  • GVScript core virtual world classes(GVSpace)
  • GVScript visual editor
  • GVScript core classes

These all build upon MPF so experienced developers can look at them as examples. However, I’ve got to get the core MPF code concepts out to give people something to work with. So with this blog is going to be the vehicle. Buckle up because the ride will be bumpy in places.