Question

I'm just looking for what it is that sets Self apart from Smalltalk.

This isn't supposed to be a Gorilla vs Shark question. I'm not looking for reasons one is better, I'm just confused as to what defines one as being distinct from the other. They both appear to be the same language to me after about 2 hours of reading up on them and mucking around with some code (Aside: I finally understand the Smalltalk version of "Everything is an object". I must say, it's bloody awesome. Haha! And I thought that C# had it nailed... but it doesn't even come close to this! XD)

Random things that I've read somewhere, some time over the past few years:

  • Smalltalk assignment and messages/message passing are the only things that aren't objects, However in Self, even these things have a place in the object framework
  • "Self is even more pure OO-wise than Smalltalk is". I haven't been able to find more concrete elaboration.
Was it helpful?

Solution

Classes and Prototypes

The most distinct difference between Self and Smalltalk is that Self does not have the notion of Classes. There is no “is an instance of” relation between an object and a class. Self rather has been one of the first prototypical object-oriented language, and in this respect a precursor to JavaScript. Hence, the typical way to create a new object in Smalltalk is instantiation whereas in Self it is cloning.

Execution and Messages

As you already have found out, the second fundamental difference is that in Self, the only notion of execution is the message send, whereas in Smalltalk, assignment and object field access also are present. Furthermore, there is no such thing as global state in Self. You can only access what you can retrieve by sending messages. Self however tracks some “well known objects”, which a newly created object can be given.

State and Slots

Pondering on the two previous points, “No classes” and “only messages”, makes it clear, that the Smalltalk distinction between and objects state and its behavior is not directly present in Self. Where Smalltalk stores state in an objects’s instances variables and behavior in method dictionaries in its class, Self uses the notion of slots, which can represent both state and behavior.

Sharing behavior

To help organizing behavior, Self not only provides prototypes but also traits. A trait is an object that only contains behavior, and which several objects share. (Moreover, there are also mixins, small portions of behavior and state, that can be composed into other objects).

Objects in Self can have parents to which messages are sent that the object itself does not understand (delegation). This creates hierarchies that can be similar to class inheritance in Smalltalk, but does not need classes.

A few Examples

Creating a new object

Smalltalk
Object new
Self:
  • a plain object: () or (||) (to make the absence of slots explicit)
  • a copied object: someObject copy

Creating an object with some fields

Smalltalk
Object subclass: #MyObjects instanceVariableNames: 'foo bar'. "…" 
MyObject new.
Self
( | foo. bar | )

Making a collection

Smalltalk
OrderedCollection new.
Self
list copy.

“Inheritance”

Smalltalk
Object subclass: #MyObject. "…"
Self
( | parent* <- list | )

Resources

I suggest reading the bibliography section on the Self webpage.

OTHER TIPS

Tobias has set out the key differences, so read his answer.

In a sense Self is Smalltalk. The difference between Self and a Smalltalk-80 such as Squeak or VisualWorks is less than the differences between Smalltalk-80 and Smalltalk-72. They appear very similar because they are related.

There's a Self phrase - "Self is like Smalltalk, only more so". You like messages? We use them for everything. You like objects? Our objects are truly self contained, not just instances of classes. You like a conceptually small language? Well, we've just got objects, slots and messages. Etc.

Knowing Smalltalk for some time and reading Wikipedia:

  1. Self:

    Prototype based

    Smalltalk:

    Class based

  2. Self:

    Since the receiver of the '_AddSlots:' primitive isn't indicated, it is "self".

    Smalltalk:

    you write self explicitely.

  3. Self:

    you add slots to objects.

    Smalltalk:

    you add slots to classes or you do it like this to objects

  4. The people, who invented and influence the 'language'/'system', are different. Self and Smalltalk can be seen as a 'system' (change your point of view), this means that you as programmer talk to the system and change it at runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top