Skip to content
Tutorials Center
My learning

Topics

Lesson 1 of 38 ยท Getting Started

What Is Smalltalk? A Pure Object Language and Living System

Meet Smalltalk: the pure object-oriented language where everything is an object and every action is a message. Learn its history, its living-image idea and how it shaped modern languages.

Smalltalk is a programming language and a programming environment in one piece. It was created at Xerox PARC in the 1970s by a team around Alan Kay, Dan Ingalls and Adele Goldberg, and it gave the world the words and habits we now call "object-oriented programming": objects, classes, messages, inheritance, windows, menus, the mouse-driven desktop and the idea of a refactoring browser. Ruby, Objective-C, Swift, Python and JavaScript all borrowed from it, often without saying so.

What makes Smalltalk special is how little there is. The whole syntax fits on a postcard. There are no keywords for if, for or class: those are ordinary messages sent to ordinary objects. Once you learn how to send a message, you know almost everything the language has to offer.

About this tutorial. The real Smalltalk systems (Pharo, Squeak, GNU Smalltalk, Cuis) cannot run inside a web page, and this site has no Smalltalk runner. Every Smalltalk snippet in this course is therefore read-only, and we show its output only when we are certain of it. Next to them you will find small JavaScript stand-ins, clearly labelled, that you can run and edit to see the underlying idea (message sending, blocks, collections). They are not Smalltalk, and they say so in a comment. To run the real thing, install Pharo (see Installing Pharo).

The big ideas

Smalltalk rests on a few rules that are applied without exception.

  1. Everything is an object. Numbers, strings, booleans, classes, blocks of code, even the compiler and the debugger are objects.
  2. Objects communicate only by sending messages. You never reach into an object; you ask it something and it decides how to answer.
  3. Every object is an instance of a class, and classes are objects too, instances of metaclasses.
  4. Classes form a single inheritance tree rooted at Object (and above it ProtoObject).
  5. The system is live. You change code while the program is running, and the debugger lets you fix a bug and resume.

Here is the flavour of the language. Do not worry about the details yet:

SMALLTALK
3 + 4.                       "send + 4 to 3"
'hello' size.                "send size to a string"
#(3 1 2) asSortedCollection. "send asSortedCollection to an array"
5 factorial.                 "send factorial to 5 -> 120"
Date today.                  "send today to the class Date"

Each line is one object followed by one message. 3 + 4 is not an operator applied to two values: it is the message + with argument 4 sent to the object 3.

The history in five steps

Year Milestone
1972 Alan Kay's group at Xerox PARC starts work on Smalltalk-72
1976-80 Smalltalk-76 and Smalltalk-80 add classes and a mature class library
1980s Books and commercial systems (ParcPlace, Digitalk, IBM) spread the language
1996 Squeak is released as a free, portable Smalltalk written in Smalltalk
2008 Pharo forks from Squeak, aiming at a clean, modern, professional system

Today you will meet Smalltalk in four main flavours:

  • Pharo: modern, actively developed, open source (MIT). It is the best choice for learning and for new projects, and it is what this course uses.
  • Squeak: the creative, multimedia-minded ancestor of Pharo, popular in education.
  • Cuis: a tiny, elegant system for people who like to read all of the source.
  • GNU Smalltalk: a command-line interpreter that reads source files, useful for scripts.

Commercial systems such as VisualWorks and Dolphin still exist, and Smalltalk is used in finance, logistics, research and teaching around the world.

The image: a world that never stops

Most languages work like this: you write source files, compile them, run the program, and the program ends. Smalltalk works differently. When you start Pharo, it loads an image: a snapshot of every object that existed the last time you saved. Your classes, your windows, your half-finished experiments, the text in your playground: all of them are objects in that snapshot, and they are just where you left them.

flowchart LR
    VM["Virtual machine<br/>(small program for your OS)"] --> IMG["Image file<br/>all objects, classes, tools"]
    CH["Changes / source files<br/>the text of the code"] --> IMG
    IMG -->|"Save"| IMG2["Updated image"]

The VM executes the image; the image contains the whole world. Saving writes the world back to disk.

Because the tools live in the image too, you can open an inspector on any object, read the source of any method, even the ones in the system, and change them. This is called live programming, and it changes how you work: instead of "edit, compile, run, hunt the bug", you write a line, run it, look at the result, and keep going.

What a message send looks like

A message has three parts: a receiver (who gets it), a selector (the name of the message) and zero or more arguments.

SMALLTALK
receiver selector.
receiver selector: argument.
receiver first: 3 second: 4.      "selector is first:second:"

The object decides what to do. A string responds to size by counting characters; a collection of other kinds responds differently. This is polymorphism in its purest form: the sender does not know or care what class the receiver is.

JS Stand-in: sending a message

Press Run (or Ctrl + Enter) to see the console output here.

No output.

When an object receives a message it has no method for, Smalltalk does not crash: it sends doesNotUnderstand: to the object, and by default that opens the debugger with a friendly list of things you can do.

Why learn Smalltalk today?

  • It makes object-oriented design click. Without static, primitives or special cases, you see objects and messages as they were meant to be.
  • The tools are the best part. The inspector, debugger and browser are examples of what other languages are still catching up to.
  • Its ideas are everywhere. Understanding Smalltalk explains why Ruby blocks, Objective-C selectors, Swift's argument labels and test-driven development look the way they do (SUnit, the first xUnit, was written in Smalltalk).
  • It is small. You can hold the whole language in your head in an afternoon.
JS Stand-in: a Smalltalk-style numeric tower

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In Smalltalk, what does the expression 3 + 4 actually mean?

    There are no operators in the usual sense. Binary selectors like + are ordinary messages, and 3 is an object that receives it.
  2. 2. What is the Smalltalk image?

    The image is a saved world of objects. Starting Pharo restores it exactly as it was saved.
  3. 3. Which of these is NOT a Smalltalk dialect or system?

    Erlang is a different language. Pharo, Squeak and Cuis are all Smalltalk systems.
  4. 4. What happens by default when an object receives a message it does not understand?

    Message sends are resolved at run time. An unknown selector triggers doesNotUnderstand:, which by default opens the debugger where you can even define the missing method and continue.

Summary

  • Smalltalk is a pure object language: everything is an object and all computation is message sending.
  • It was born at Xerox PARC and shaped most later object-oriented languages and tools.
  • Pharo is the modern, open-source system used in this course; Squeak, Cuis and GNU Smalltalk are relatives.
  • The image is a living snapshot of the whole system, which makes live programming possible.
  • This site cannot run Smalltalk, so snippets are read-only and the runnable examples are labelled JavaScript stand-ins.

Next: Installing Pharo and a Tour of the Environment