Self (programming language)

Self [ sɛlf ] is a programming language that was designed out of Randall B. Smith and David Ungar, especially in terms of expressiveness and malleability. To achieve these goals, a purely prototype-based object model with uniform access to state and behavior of objects, ie, developed on their attributes and methods. Unlike other programming languages ​​, it is possible to self, to inherit the state of objects and dynamically adjust the inheritance at runtime.

The version 4.3 of the Sun was published in June 2006. It runs on Intel - and PowerPC-based Apple computers and on Sun SPARC, but not on Linux or Microsoft Windows. The development is no longer operated by Sun. Version 4.4 runs on Mac OS X and Linux. Since February 2011, there is an experimental version 4.5.

Ideas and concepts that have their primary origin in the programming language Self, were taken over the years both in the Squeak Smalltalk system, as continued in programming languages ​​such as slate or io.

The outstanding feature is probably the Self- Self- universe, a type of graphical user interface ( GUI), within which can be interacted with the self- runtime system. An interaction takes place in the control of the mouse and / or keyboard. Is visualized by the Self- universe of the Morphic GUI frameworks. If a person enters the Self- universe, so it is always about the lobby, an allusion to the lobby of a hotel. All of which are present in the system objects, modules, namespaces and traits in her. The concept of (programming ) universe and the Morphic concept has been implemented in Squeak Smalltalk almost identical system.

Despite the various ports, one should remember that it is a more academically motivated task in the programming language Self. Nevertheless, had and have the proven innovations in Self influence to newer object-oriented programming languages.

  • 9.1 Related Programming

History

Self was originally designed in 1986 by David Ungar and Randall B. Smith during their work at Xerox Parc Institute. Their goal was, after Smalltalk-80 had been published, further advancing the software technology. They switched to Stanford University and published the first working compiler in the following year. The first complete self- system was released in 1990; in the following year, the group moved to Sun Microsystems where the Self- System was used as a testing ground for the development. Urs Hölzle here came about, who developed new compiler and VM techniques and was involved in the development of programming Strong Talk. In 1995, the development at Sun Microsystems was officially set: "Self is 4.0, in a sense, the culmination of the self - project, which is not officially allowed to proceed at Sun. " However, there was the development group at Stanford University as well as various other initiatives. Despite the official stops the version 4.1.6 was released in September 2002. In April 2004, then the version 4.2 was released in June 2006, version 4.3. Since July 2010 there is a version 4.4. An experimental version 4.5 has been around since February 2011.

The development environment

The self- system can be understood as a prototype-based Smalltalk variant. The developers describe the language as Smalltalk dialect and mean that the syntax of the language and the object library largely based on Smalltalk. The class browser of Smalltalk was replaced by an object browser.

As Smalltalk is based on a self runtime environment and a virtual machine. Self- need programs, just like other systems based on virtual machines, always the associated memory environment to be executed can. As a result, applications are often delivered as a memory image. This dump is also called snapshot.

An alternative to the delivery of snapshots are text files that can be exported and imported via the so-called transporter in the changes to the system or entire modules. These text files can be edited with any editor. They are similar to a C source code, but much more powerful. The entire system can be controlled with it. Since these text files can also be read automatically with the start of the system, self can be used as a scripting language like Perl.

The typical size of a snapshot is about 13 MB for a complete system with JIT compiler, interpreter, and the development environment. The inherited from Smalltalk advantage is that the work can be stored on the system at any time, even in the middle of a calculation, be interrupted and snapshots. All changes, so what programming, a drawing or any work with the system corresponds to classical systems, can be present again at the next reboot on request. The system wakes up where it left off. Self is persistent.

The Self-development environment allows source code, modify objects, inheritance, the object hierarchy or individual values ​​at runtime. Is that possible. Due to the ability to multitask and a seamlessly integrated into the system debugger This leads to an incremental type of "on the fly " developing. Some modern methods of software development, such as the Agile software development or the Adaptive Software Development, propagate like.

Thus, the development environment to the rapid and continuous change individual objects is tailored. The refactoring of the " object" designs is almost as simple as removing a method via drag and drop, in order to be able to assign a new object. Simpler tasks such as creating test methods can be overcome by a copy. The appropriate method is then drawn into the object copy in order to change it so you can. Compared to traditional systems, only the object just newly generated also has new source code. It is therefore not necessary to recompile code in order to test it can. Once it is ensured that the test method according to the specification functions, they can be copied back to the output object.

Language description

Below are just a first impression should be taught that language. For more detailed information, please refer to The Self Language and Teaching Self and Prototype -Based Programming.

Self is an object oriented, prototype-based programming language. The basis is that a few simple constructs: prototypes, slots, and behavior. In contrast to the concepts of Smalltalk, and many other programming languages ​​, there are no classes or variables. The programming model is essentially based on communicating objects and a simple form of inheritance.

In Self no programs are written in the proper sense - instead, describes the "Self - universe ". There are only objects that communicate with each other by sending messages. Send a message This corresponds to a procedure call in the classical programming. New objects are created by cloning existing objects.

Through the prototype design an interactive programming is possible: The programmer interacts with the objects in Self- universe.

In Self does not distinguish between the state of an object and its behavior. The state of an object results from its properties, ie the values ​​of its attributes. The behavior of an object is described in his methods. Characterized in that there is no difference between the state and the behavior of the gap is reduced, which exists in other programming languages ​​between objects, procedures and variables. In Self everything is one.

For example, delivers the call to a property - unless the object or one of its ancestors has this property because - their value:

Aperson name In this statement, the name of the object aperson property is retrieved or queried. The following statement of the same property is assigned a value:

Aperson name: ' myself ' language constructs

Objects consist of (theoretically) unlimited number of slots ( slots). One slot has a name and an attribute (value) or a method ( procedure ) included. In any case it is an object that he receives. An object is thus composed of a plurality of slots for objects that can be accessed by the name or a.

A method object contains one or more statements that are executed when the method object is called. An attribute object provides reset itself when it is invoked as a method object.

New objects are created by cloning. To this end, a matching object is used as a prototype, so to speak, as a template. Each object can be used as a prototype.

A short program

Here the classic Hello World program:

'Hello, World! ' print. The dot at the end of the statement causes the return of the value - which actually takes place with all messages - is suppressed or avoided. Here again in a more complex form:

( desktop activeWindow ) draw: (label widget copy label: 'Hello, World! '). Explanation: First, the desktop object on the active window will be prompted. The desktop object looks to consult its list of the current window and returns the resulting object. This object is entered in the slot named draw a previously generated copy of the label widget object. Before that happens, the label widget- copy has already been sent the message that it should create a slot with the label name and then the value of Hello, World! is to store.

Heredity

Theoretically, each self- object is a distinct entity. There are no classes, no meta - classes, etc. to specify the properties and behavior of an object. Changes to the object itself does not influence the behavior of other objects. In individual cases, however, this would make sense. Basically, an object understands only the messages that can be uniquely assigned to one of its slots. However, reference one or more slots on a parent object, then the object is able to delegate messages to that parent objects, in that it itself is not able to interpret them. In this way, self- managed tasks that would have taken the vehicle of inheritance in traditional object-oriented languages ​​. This procedure is also used to implement namespaces.

In order to illustrate the relationship of inheritance better, is to be assumed at this point from an object named bank account. This is to be used in a simple accounting application. It stands to deposit the bank account object with the methods and equip stand out. Additional slots for ease of data are also required. The specified object is just a prototype, but is already constitute a fully functional bank account

If you create a clone of the object bank account for " Bob's Account ", you get a copy that is the same as the original prototype. A more effective approach, however, is to create a simple object called traits object that contains all the elements that one would normally associate with a class.

Similar to the current example, the object bank account would neither deposit nor have as a logical consequence of a pay method. Rather it now has a parent object containing these methods. In this way it is possible to produce numerous copies of the bank account object whose behavior can be altered by a single change in the parent object.

How is the situation described by the traditional classes an OO language is different? What well mean the following construct:

MyObject parent: someother object. This construct changed the "class" of myObject at run time by setting the value associated with the slot parent * is changed (the asterisk is part of the slot name and therefore not part of the message that this slot receives ).

Add slots

At this point the question arises how to make copies of a self - object must be modified to include these new slots. If one uses the graphical Self- programming environment, this is more fairly simple. Programmatically seen it makes the most sense to create a so-called mirror - object of the object and then modify. To do this sends Mirror object corresponding message.

A path that leads quickly to the goal is the primitive _AddSlots: to use. A primitive has the same syntax as a normal keyword message. However, a name that begins with an underscore. The _AddSlots primitive is now considered obsolete; because of its brevity, it is used here anyway.

One of the first examples dealt with the refactoring of a simple class called vehicle. The refactoring was necessary to distinguish between trucks and passenger can. If you try to implement the refactoring in Self, this looks something like this:

_AddSlots: (| Vehicle <- ( | * parent = traits clonable | ) | ). As the recipient of the _AddSlots: primitive has not been specified, it is automatically "self ". When an expression is entered and executed within the shell prompt the development environment, it is the object that it receives resulting messages always the lobby object. The _AddSlots to: passed argument is the object that is copied to the receiver object. In this case, it is an object literal with exactly one slot. The name of the slot is vehicle, and its value is another object literal. The notation manner "<-" implies a further slot called vehicle: that is necessary to change the value of the first slot.

The "= " indicates a slot of constant value. For this reason, there is no corresponding parent: slot. The object literal representing the initial value vehicle, has a slot in order to react to news of cloning can. An object that is actually empty, by | shown or simply () (|). Such an object is not able to receive messages.

Vehicle _AddSlots: ( | name <- 'automobile ' | ). In this example, the message receiver is the previous object, both in addition to the parent * slot a name and a name: contains slot.

_AddSlots: (| Sportscar <- vehicle copy | ).     Sportscar _AddSlots: (| driveToWork = ( '' some code, this is a method '' ) | ). Despite the fact that it previously vehicle at the objects and Sportscar these were identical objects, the current object now includes a slot which is assigned a method that did not exist before. Methods may incidentally be included only in slots with a constant value.

_AddSlots: (| Porsche911 <- Sportscar copy | ).     Porsche911 name: ' Bob's Porsche '.

Versions

  • 4.0: running on SPARC-based Sun workstations running SunOS 4.1.x, Solaris 2.3, or Solaris 2.4 operating system
  • 4.1.6: runs as an application on Mac OS X. Support for Mac OS 9 was set
  • 4.2.1: run on G3 Macs
  • 4.3 also runs on Intel -based Macs
  • 4.4: runs on Mac OS X and Linux ( x86)
721988
de