Self
Self was developed at Xerox PARC and Sun Microsystems in the late 1980s by David Ungar and Randall Smith, and is a descendant of Smalltalk. It asks what happens if you remove classes altogether: there are only objects, and you create new ones by cloning.
Paradigm: Object-Oriented Programming
What Makes Self Special
- No classes. Objects hold named slots. Instead of instantiating a class, you copy an object that already looks like what you want.
- Slots hold data and behavior alike. A slot may contain a value, a method or a reference to another object. Reading a variable and calling a method look identical from the outside.
- Inheritance by delegation. An object has parent slots. If a message is not understood by the object, it is passed to its parents, which replaces class inheritance.
- A direct, visual world. Self's Morphic interface let you grab and edit live objects on screen, and this style influenced later user interfaces.
- Its ideas spread widely. JavaScript's prototype model comes straight from Self, and its dynamic optimization techniques influenced modern JIT engines such as HotSpot and V8.
Example: A point object, copied instead of instantiated
"Typed at the Self shell prompt"
_AddSlots: (| point = (|
parent* = traits clonable.
x <- 0.
y <- 0.
distanceFromOrigin = ( (x * x + y * y) sqrt )
|) |).
_AddSlots: (| p <- point copy |).
p x: 3.
p y: 4.
p distanceFromOrigin printLine.
How It Works
x <- 0defines a data slot with an initial value and creates the assignment slotx:automatically.parent* = traits clonableis a parent slot: the asterisk marks it as a place to look up messages the object does not understand. It suppliescopy.distanceFromOriginis a slot containing code, so data and methods live side by side in the same object.point copyclones the prototype. Settingxandyand asking the distance prints5.0.- The listing is a compact sketch of the syntax; the Self manual documents the shell commands in detail.
History and Where It Is Used
Self is mostly a research language today, but its influence is huge: JavaScript objects, the Io prototype model, and dynamic optimization techniques later used in HotSpot and V8 all trace back to it. The Self community keeps the system alive, and the Morphic interface lives on in Squeak and Pharo.
Learn More
- Self language site
- Self (Wikipedia)
- Back to Object-Oriented Programming or the PGP roadmap.