Selfish is a minimalistic yet powerful OO extension for the
Tcl language.
It, like Self, is a so-called prototype object system. It models itself on
the natural world where things are not instantiated, but cloned. Any object
can be cloned. Any object can inherit from any other object or objects.
Relationships can be changed dynamically.
Tcl is a powerful, yet simple free scripting language allowing programmers to
extend and even change features of the language dynamically.
Features
- Minimalistic, simple, powerful.
- Totally dynamic. All relationships and even parts of the extension can be
changed at run time.
- Methods and fields are one and the same. They are slots. Have a Point object? Want
the X co-ordinate to be calculated somehow? Change the slot to something
with code. The callers will not even know something has changed.
- Written in pure Tcl
Why a prototype system?
It is a very simple, very flexible system. Forget about classes,
meta-classes, virtual methods and so forth. Objects are objects.
Self-contained entities which communicate with other objects. A prototype is
a real, working object in itself, which can be cloned to create new objects.
Instead of a class declaring features for its instances, you have something
that can be used as-such and copied, if necessary.
Take the classic car example. You can create a working car, with all of its
important attributes in place. A prototypical car with shared functionality
for all cars. Note that this prototype can be a fully functional car in its
own right. We can create another object and make it inherit from the
previously created prototypical car, perhaps we'll create a
Caterham 7. That
is naturally a fully operational car as well (unlike if we had made it a class,
which would only be a template). We can modify it and extend it with
features from a Caterham 7. To make new 7s we can clone that one. As
people like to modify and enhance their 7s, each of these clones can be
tweaked freely. They all inherit from the same prototypical car, which might
contain knowledge about how to fix a car or how best to use pedals. Shared
information. Prototype object systems do a good job of mapping to the real
world.
The prototype object model is a powerful one. So powerful that a class-based
object system can be built on top of it, if needed. Yet it is simple. Much
like Tcl itself. In fact, one of the main papers describing Self uses the
line "The Power of Simplicity", which could easily be used to describe Tcl
as well.
Selfish is not Self. You can use all the normal features of Tcl. Blocks of
code are not objects, they are strings. Selfish objects are actually
accessed by Tcl commands, which are created dynamically. It fits neatly on
top of the language it extends.
Documentation
The download package includes documentation, which can also be read
separately here.
Download
This is the first release, 1.0. 6th October 2006. Selfish is not limited by
any license. It can be used and modified freely for any purposes. Credit,
where due, is nice, but not necessary.
- The only external dependency is for Tcl 8.4, which is available
here, or for binaries for
many platforms go here
. OSX Tiger has Tcl 8.4 pre-installed.
- The Selfish package can be downloaded from
here
Contact
For feedback, both positive and negative, or fixes, contact
Kristoffer Lawson
Disclaimer
SEVEN and 7 are registered trade marks of Caterham Car Sales & Coachworks
Limited. I mentioned it here as merely an example.