The introduction to On To Smalltalk follows. Additional information about this book, along with access to software, is available via http://www.ai.mit.edu/people/phw/Books/

How On To Smalltalk Teaches You Smalltalk

The purpose of this book is to help you learn the essentials of Smalltalk programming. In this section, you learn why you should learn Smalltalk and how this book is organized.
Object-oriented programming languages, such as Smalltalk, encourage you to design programs around classes, such as the Integer class, along with classes that you define yourself. Typically, you define classes and class hierarchies that reflect important general properties of individual nails, horseshoes, horses, kingdoms, or whatever else happens to come up naturally in your application.
In the vernacular of Smalltalk programming, messages are sent to receivers, and receivers return answers. To do the necessary computation, Smalltalk finds the appropriate method, given the receiver and the message, and that method specifies exactly how the computation is to be performed.

For example, Smalltalk allows you to send a message, sqrt, to a receiver, 2, which is a member of the Integer class. To handle the message, Smalltalk finds the appropriate way to compute the required square root for receivers belonging to the Integer class; then, Smalltalk produces the answer, 1.41421, which is an instance of the Float class.


Visually, the receiver has center stage; 2 is a receiver that knows how to find a method that can deal with the sqrt message.
              Receiver
Message          |
  |              v
  v          *-------*
sqrt ------> |       |
             |   2   |
1.41421 <--- |       |
  ^          *-------*
  |
Answer

In contrast, procedure-oriented programming languages, such as C, encourage you to think in terms of functions and procedures, instead of in terms of classes and class hierarchies.

Thus, to compute the square root of 2 using a procedure-oriented programming language, you must identify the appropriate function, which, when applied to 2---a datum of the integer data type---answers 1.41421, the function's value. Visually, the function has center stage; 2 is just the function's argument:

           Data-type specific function
             |
Argument     |                             Value returned    
  |          v                               |
*-*        *---------------------*           |
v          |                     |           v
2 -------> | integer-square-root |-------> 1.41421
           |                     |
           *---------------------*

In this book, you learn what object-oriented means and why many programmers prefer object-oriented languages. For now, it suffices to know that Smalltalk is an object-oriented programming language, whereas most programs have been written by programmers using procedure-oriented programming languages.
Among the object-oriented programming languages, Smalltalk has attractive characteristics, such as the following:
You learn that Smalltalk is said to be a pure object-oriented language because every entity in Smalltalk is an object and every object can receive and send messages. Being a pure object-oriented language is one of Smalltalk's distinguishing strengths.
The enormous power of Smalltalk development environments is derived from an unusual armamentarium of powerful tools:
Also, Smalltalk provides for automatic memory recycling. When you use a language such as C++, you have to remember to free the memory allocated to program elements, such as class instances, once you are finished with them. Failing to free memory produces a memory leak that may exhaust all the memory available to your program, leading either to erratic behavior or to a total crash.

Smalltalk frees memory automatically, by performing automatic garbage collection, so you never need to worry about memory leaks, or to waste time looking for one. Thus, you are more productive, and are less likely to be driven crazy by doing tedious, mind-numbing debugging.


There are two principal reasons why you should learn Smalltalk:

Capabilities of a commercial Smalltalk, VisualWorks, are also explained.


Four principles determined this introductory book's organization and style:
To get you up and running in Smalltalk quickly, the sections in this book generally supply you with the most useful approach to each programming need, be it to display characters on your screen, to define a new method, or to read information from a file.
To answer your basic questions explicitly, this book is divided into section that generally focus on one issue, which is plainly announced in the title of the section. Accordingly, you see titles such as the following:
To encourage you to develop a personal library of solutions to standard programming problems, this book introduces many useful, productivity-increasing, general-purpose, templatelike patterns---sometimes called idioms by experienced programmers---that you can fill in to achieve particular-purpose goals.

Idioms are introduced because learning to program involves more than learning to use programming-language primitives, just as learning to speak a human language involves more than learning to use vocabulary words.


To deepen your understanding of the art of good programming practice, this book emphasizes the value of such ideas as data abstraction and procedure abstraction, along with principles such as the explicit-representation principle, the modularity principle, the no-duplication principle, the look-it-up principle, and the is-a versus has-a principle.
In this book, single-idea segments, analogous to slides, are arranged in sections that are analogous to slide shows. The segments come in several varieties: basic segments explain essential ideas; sidetrip segments introduce interesting, but skippable, ideas; practice segments provide opportunities to experiment with new ideas; and highlights segments summarize important points.
Finally, the book develops simple, yet realistic, Smalltalk programs, which you see in many versions as your understanding of the language increases. In its ultimate version, one of the programs rates foods according to their protein, carbohydrate, and fat content.


Highlights