Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between Self and Smalltalk

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.
like image 507
TheIronKnuckle Avatar asked Jun 06 '13 10:06

TheIronKnuckle


People also ask

How is self used in Smalltalk?

Description. 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.

What makes Smalltalk unique?

Smalltalk was one of the earliest object-oriented (OO) languages (with others like Simula and Eiffel) and can be said to be extremely "pure" in an OO sense: Everything is an object and objects are only communicated with via the sending of messages. No primitives (no int s, boolean s etc)

What type of language is Smalltalk?

Smalltalk is a "pure" object-oriented programming language, meaning that, unlike C++ and Java, there is no difference between values which are objects and values which are primitive types.

Are classes objects in Smalltalk?

In Smalltalk, everything is an object, and classes act as descriptions of objects. Classes are used to define the set of messages an instance of that class responds to, as well as the variables contained in every instance of that class.


3 Answers

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.

like image 75
2 revs, 2 users 97% Avatar answered Oct 17 '22 19:10

2 revs, 2 users 97%


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.

like image 11
Russell Allen Avatar answered Oct 17 '22 18:10

Russell Allen


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.

like image 3
User Avatar answered Oct 17 '22 17:10

User