- Self (programming language)
Infobox programming language
name = Self
paradigm = object-oriented prototype-based
year = 1986
David Ungar, Randall Smith
developer = David Ungar, Randall Smith,
Stanford University, Sun Microsystems
latest release version = 4.3
latest release date = June 2006
typing = dynamic, strong
implementations = Self
Self is an object-oriented programming language based on the concept of "prototypes". It was used mainly as an experimental test system for language design in the 1980s and 1990s. In 2006, Self was still being developed as part of the Klein project, which was a Self virtual machine written fully in Self. The latest major version is 4.3, which was released in July 2006. As of 2007, the Klein project is no longer active.
Self was designed mostly by
David Ungarand Randall Smith in 1986 while working at Xerox PARC. Their objective was to push forward the state of the art in object-oriented programming language research, once Smalltalk-80 was released by the labs and began to be taken seriously by the industry. They moved to Stanford Universityand continued work on the language, building the first working Self compiler in 1987. At that point, focus changed to attempting to bring up an entire system for Self, as opposed to just the language.
The first public release was in 1990, and the next year the team moved to
Sun Microsystemswhere they continued work on the language. Several new releases followed until falling largely dormant in 1995 with the 4.0 version. The latest 4.2 version was released in 2004 and runs on Mac OS Xand Solaris.
Self also inspired a number of languages based on its concepts. Most notable, perhaps, was the NewtonScript language for the
Prototype-based programming languages
Traditional class-based OO languages are based on a deep-rooted duality:
#Classes define the basic qualities and behaviours of objects.
#Object instances are particular manifestations of a class.
For example, suppose objects of the
Vehicleclass have a "name" and the ability to perform various actions, such as "drive to work" and "deliver construction materials".
Porsche 911is a particular object (instance) of the class
Vehicle, with the name "Porsche 911". In theory one can then send a message to
Porsche 911, telling it to "deliver construction materials".
This example shows one of the problems with this approach: Porsches are not able to carry and deliver construction materials (in any meaningful sense), but this is a capability that
Vehicles are modelled to have. A more useful model arises from use
subclassingto create specializations of
Vehicle; for example
Flatbed Truck. Only objects of the class
Flatbed Truckneed provide a mechanism to "deliver construction materials"; sports cars, which are ill suited to that sort of work, need only drive fast. However, this deeper model requires more insight, which may only come as issues arise.
This issue is one of the motivating factors behind prototypes. Unless one can predict with certainty what qualities a set of objects and classes will have in the distant future, one cannot design a class hierarchy properly. All too often the program would eventually need added behaviours, and sections of the system would need to be re-designed (or refactored) to break out the objects in a different way.Fact|date=February 2007 Experience with early OO languages like
Smalltalkshowed that this sort of issue came up again and again. Systems would tend to grow to a point and then become very rigid, as the basic classes deep below the programmer's code grew to be simply "wrong". Without some way to easily change the original class, serious problems could arise.Fact|date=February 2007
Dynamic languages such as Smalltalk allowed for this sort of change via well-known methods in the classes; by changing the class, the objects based on it would change their behaviour. However, such changes had to be done very carefully, as other objects based on the same class might be expecting this "wrong" behavior: "wrong" is often dependent on the context. (This is one form of the
fragile base class problem.) Further, in languages like C++, where subclasses can be compiled separately from superclasses, a change to a superclass can actually break precompiled subclass methods. (This is another form of the fragile base class problem, and also one form of the fragile binary interface problem.)
In Self, and other prototype-based languages, the duality between classes and object instances is eliminated.
Instead of having an "instance" of an object that is based on some "class", in Self one makes a copy of an existing object, and changes it. So
Porsche 911would be created by making a copy of an existing "Vehicle" object, and then adding the "drive very fast" method. Basic objects that are used primarily to make copies are known as "prototypes". This technique is claimed to greatly simplify dynamism. If an existing object (or set of objects) proves to be an inadequate model, a programmer may simply create a modified object with the correct behavior, and use that instead. Code which uses the existing objects is not changed.
Description of the language
Self objects are a collection of "slots". Slots are accessor methods that return values, and placing a colon after the name of a slot sets the value. For example, for a slot called "name", myPerson namereturns the value in name, and myPerson name:'foo'sets it.
Self, like Smalltalk, uses "blocks" for flow control and other duties. Methods are objects containing code in addition to slots (which they use for arguments and temporary values), and can be placed in a Self slot just like any other object: a number for example. The syntax remains the same in either case.
Note that there is no distinction in Self between fields and methods: everything is a slot. Since accessing slots via messages forms the majority of the syntax in Self, many messages are sent to "self", and the "self" can be left off (hence the name).
The syntax for accessing slots is similar to that of Smalltalk. Three kinds of messages are available:;unary :
"receiver" slot_name;binary :
"receiver" + "argument";keyword :
"receiver" keyword: "arg1" With: "arg2"
All messages return results, so the receiver (if present) and arguments can be themselves the result of other messages. Following a message by a period means Self will discard the returned value. For example:
'Hello, World!' print.
This is the Self version of the
hello worldprogram. The
'syntax indicates a literal string object. Other literals include numbers, blocks and general objects.
Grouping can be forced by using parentheses. In the absence of explicit grouping, the unary messages are considered to have the highest precedence followed by binary (grouping left to right) and the keywords having the lowest. The use of keywords for assignment would lead to some extra parenthesis where expressions also had keyword messages, so to avoid that Self requires that the first part of a keyword message selector start with a lowercase letter, and subsequent parts start with an uppercase letter.
valid: base bottom between: ligature bottom + height And: base top / scale factor.
can be parsed unambiguously, and means the same as:
valid: ((base bottom) between: ((ligature bottom) + height) And: ((base top) / (scale factor))).
In Smalltalk-80, the same expression would look written as:
valid := self base bottom between: self ligature bottom + self height and: self base top / self scale factor.
scalewere not instance variables of
selfbut were, in fact, methods.
Making new objects
Consider a slightly more complex example:
labelWidget copy label: 'Hello, World!'.
makes a copy of the "labelWidget" object with the copy message (no shortcut this time), then sends it a message to put "Hello, World" into the slot called "label". Now to do something with it:
(desktop activeWindow) draw: (labelWidget copy label: 'Hello, World!').
In this case the
(desktop activeWindow)is performed first, returning the active window from the list of windows that the desktop object knows about. Next (read inner to outer, left to right) the code we examined earlier returns the labelWidget. Finally the widget is sent into the draw slot of the active window.
In theory, every Self object is a stand-alone entity. Self has neither classes nor meta-classes. Changes to a particular object don't affect any other, but in some cases it is desirable if they did. Normally an object can understand only messages corresponding to its local slots, but by having one or more slots indicating "parent" objects, an object can delegate any message it doesn't understand itself to the parent object. Any slot can be made a parent pointer by adding an asterisk as a suffix. In this way Self handles duties that would use inheritance in class-based languages. Delegation can also be used to implement features such as namespaces and
For example, suppose an object is defined called "bank account", that is used in a simple book keeping application. Usually, this object would be created with the methods inside, perhaps "deposit" and "withdraw", and any data slots needed by them. This is a prototype, which is only special in the way it is used since it also happens to be a fully functional bank account.
Making a clone of this object for "Bob's account" will create a new object which starts out exactly like the prototype. In this case we have copied the slots including the methods and any data. However a more common solution is to first make a more simple object called a traits object which contains the items that one would normally associate with a class.
In this example the "bank account" object would not have the deposit and withdraw method, but would have as a parent an object that did. In this way many copies of the bank account object can be made, but we can still change the behaviour of them all by changing the slots in that root object.
How is this any different from a traditional class? Well consider the meaning of:
myObject parent: someOtherObject.
This excerpt changes the "class" of myObject at runtime by changing the value associated with the 'parent*' slot (the asterisk is part of the slot name, but not the corresponding messages). Unlike with inheritance or lexical scoping, the delegate object can be modified at runtime.
Objects in Self can be modified to include additional slots. This can be done using the graphical programming environment, or with the primitive '_AddSlots:'. A primitive has the same syntax as a normal keyword message, but its name starts with the underscore character. The _AddSlots primitive should be avoided because it is a left over from early implementations. However, we will show it in the example below because it makes the code shorter.
An earlier example was about refactoring a simple class called Vehicle in order to be able to differentiate the behaviour between cars and trucks. In Self one would accomplish this something like this:
_AddSlots: (| vehicle <- (|parent* = traits clonable|) |).
Since the receiver of the '_AddSlots:' primitive isn't indicated, it is "self". In the case of expressions typed at the prompt, that is an object called the "lobby". The argument for '_AddSlots:' is the object whose slots will be copied over to the receiver. In this case it is a literal object with exactly one slot. The slot's name is 'vehicle' and its value is another literal object. The "<-" notation implies a second slot called 'vehicle:' which can be used to change the first slot's value.
The "=" indicates a constant slot, so there is no corresponding 'parent:'. The literal object that is the initial value of 'vehicle' includes a single slot so it can understand messages related to cloning. A truly empty object, indicated as (| |) or more simply as (), cannot receive any messages at all.
vehicle _AddSlots: (| name <- 'automobile'|).
Here the receiver is the previous object, which now will include 'name' and 'name:' slots in addition to 'parent*'.
_AddSlots: (| sportsCar <- vehicle copy |). sportsCar _AddSlots: (| driveToWork = ("some code, this is a method") |).
Though previously 'vehicle' and 'sportsCar' were exactly alike, now the latter includes a new slot with a method that the original doesn't have. Methods can only be included in constant slots.
_AddSlots: (| porsche911 <- sportsCar copy |). porsche911 name:'Bobs Porsche'.
The new object 'porsche911' started out exactly like 'sportsCar', but the last message changed the value of its 'name' slot. Note that both still have exactly the same slots even though one of them has a different value.
One feature of Self is that it is based on the same sort of
virtual machinesystem that earlier Smalltalk systems used. That is, programs are not stand-aloneentities as they are in languages such as C, but need their entire memory environment in order to run. This requires that applications be shipped in chunks of saved memory known as "snapshots" which tend to be large and unwieldy. Fact|date=February 2007 However, due to this, the Self environment can provide powerful debugging tools. One can stop programs at any point, change values and code, and continue running where one left off. This sort of "on the fly" development delivers greater productivity. Fact|date=February 2007
In addition, the environment is tailored to the rapid and continual change of the objects in the system. Refactoring a "class" design is as simple as dragging methods out of the existing ancestors into new ones. Simple tasks like test methods can be handled by making a copy, dragging the method into the copy, then changing it. Unlike traditional systems, only the changed object has the new code, and nothing has to be rebuilt in order to test it. If the method works, it can simply be dragged back into the ancestor.
Self VMs achieved performance of approximately half the speed of optimised C on some benchmarks. [http://research.sun.com/jtech/pubs/97-pep.ps]
This was achieved by
Just-in-time compilationtechniques which were pioneered and improved in Self research to make a high level language perform this well.
The garbage collectors for Self uses generational garbage collection which segregates objects by age. By using the memory management system to record page writes a write-barrier can be maintained. This technique gives excellent performance, although after running for some time a full garbage collection can occur, taking considerable time.
The run time system selectively flattens call structures. This gives modest speedups in itself, but allows extensive caching of type information and multiple versions of code for different caller types. This removes the need to do many method lookups and permits conditional branch statements and hard-coded calls to be inserted- often giving C-like performance with no loss of generality at the language level, but on a fully garbage collected system.
* [http://research.sun.com/self/ Self Home Page at Sun Microsystems]
* [http://www.cs.ucsb.edu/~urs/oocsb/self/papers/papers.html Papers on Self from UCSB (mirror for the Sun papers page)]
* [http://www.cetus-links.org/oo_self.html Self resources at Cetus Links]
* [http://www.merlintec.com/lsi/ Merlin Project]
* [http://gliebe.de/self/index.html Self ported to Linux (without many optimizations)]
* [http://selfguru.sourceforge.net/ Automated Refactoring application on sourceforge.net, written for and in Self]
* [http://www.self-support.com/ Gordon's Page on Self]
* [http://community.schemewiki.org/?prometheus Prometheus object system on the Community Scheme Wiki]
* [http://www.smalltalk.org.br/movies/ Video demonstrating self]
* [http://www.ag-nbi.de/research/dself/ dSelf: distributed extension to the delegation and language SELF]
Cecil programming language
Smalltalk programming language
Io programming language
Lua programming language
Wikimedia Foundation. 2010.
Look at other dictionaries:
Lua (programming language) — Infobox programming language name = Lua paradigm = Multi paradigm: scripting, imperative, functional year = 1993 designer = Roberto Ierusalimschy Waldemar Celes Luiz Henrique de Figueiredo developer = latest release version = 5.1.4 latest release … Wikipedia
Slate (programming language) — Infobox programming language name = Slate paradigm = Prototype based year = 2003 designer = developer = The TUNES Project for a Free Reflective Computing System latest release version = 0.3.5 latest release date = August 10, 2005 typing = strong … Wikipedia
Python (programming language) — infobox programming language name = Python paradigm = multi paradigm: object oriented, imperative, functional year = 1991 designer = Guido van Rossum developer = Python Software Foundation latest release version = 2.6 latest release date =… … Wikipedia
Lisp (programming language) — Infobox programming language name = Lisp paradigm = multi paradigm: functional, procedural, reflective generation = 3GL year = 1958 designer = John McCarthy developer = Steve Russell, Timothy P. Hart, and Mike Levin latest release version =… … Wikipedia
Pascal (programming language) — Pascal Paradigm(s) imperative, structured Appeared in 1970 Designed by Niklaus Wirth Typing discipline static, strong, safe … Wikipedia
computer programming language — Introduction any of various languages for expressing a set of detailed instructions for a digital computer. Such instructions can be executed directly when they are in the computer manufacturer specific numerical form known as machine… … Universalium
Oxygene (programming language) — Oxygene Developer RemObjects Software Stable release 3.0.21 (August 29, 2009; 2 years ago (2009 08 29)) Influenced by Object Pas … Wikipedia
Newspeak (programming language) — Newspeak Paradigm(s) object oriented, functional Appeared in 2006 Designed by Gilad Bracha Developer Gilad Bracha, Peter von der Ahé, Vassili Bykov, Yaron Kashai, William Maddox, Eliot Miranda Stable releas … Wikipedia
Io (programming language) — Infobox programming language name = Io paradigm = object oriented prototype based year = 2002 designer = Steve Dekorte developer = Steve Dekorte (and others) latest release version = 20060704 latest release date = July 4, 2006 typing = dynamic,… … Wikipedia
T (programming language) — The T programming language is a dialect of the Scheme programming language developed in the early 1980s by Jonathan A. Rees and Norman I. Adams of Yale University as an experiment in language design and implementation. T s purpose is to test the… … Wikipedia