[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Prototypes ...



Hello Self world ...

I was wondering if anybody out there, besides me, has run into
problems with the concept of prototypes.  I have been working in
Smalltalk for a long time now and I am quite used to having to do a
new on a class to get a fresh instance.  In most cases the new
operation is written to send an initialize message to the new
instance, just to put the instance in a reasonable state (or in a
prototypical state, in our case).

This is not as clean as being able to build the prototypical object
and have users copy this prototype, but it gives me some protection
from destroying the prototype.  In the case of Smalltalk I would have
to change the initialize method in order to change the prototype, and
in Self I would simply modify THE prototype itself.  The problem is
that it ends up costing a fair amount in security, if I screw up and
pass THE prototype to some other object, and that other object does
some destructive operations on THE prototype, THE prototype is forever
destroyed (of course we can load it in again, since everything is in
files, but that's not the point).  In some cases this is not so bad,
but in general I think it is.

Here's an example, I'm currently writing an Emacs like editor in Self
(running in the graphical UI).  This editor needs to do some accessing
operations on individual lines of a paragraph, I would like these
operations to be done in O(1) (constant time, no iterative look up to
find the appropriate index).  So I then proceeded to implement the
Smalltalk OrderedCollections (which Danny and I are releasing I think
today).  Now that I have this new collection, I copied a paragraph and
set it's lines slot to be an OrderedCollection, and did some testing.
Found some bugs and went on, but in one of my tests I forgot to copy
the prototypical paragraph and inadvertenly set it's lines slot to an
OrderedCollection.  Well this kind of killed the UI, since I still had
some bugs, so I had to exit and come back in, rebuilding everything
again.

I can site more examples of this, but hopefully you get the point.
Now for me to get to the real point, does anybody think that some kind
of protection mechanism should be provided for prototypes, so that
they can be "locked" in general, but can be unlocked on a need basis.
I am not one to like syntactic sugar solutions, but I haven't been
able to really come up with a good scheme of doing this.  One scenario
I can think of is where the where you have a prototypeHolder, aske the
holder for a copy and it returns you the prototype.  If you want to do
anything to the prototype itself simply ask the holder for the
prototype and then you can modify.

This is probably not as clean as it could be, so what I'm looking for
is some more ideas on how to solve this type of problem, and possibly
influence the Self gods to include them in the Self environment.

        Keep being Self-ish ...

:) Eric Arseneau :) eat@scs.carleton.ca