Issue #25: Smalltalk

The Absolute No-Frills Quite Ignorant Very Incomplete And Certainly Flawed Beginner’s Guide To Smalltalk

For the second month in a row, this publication focus its spotlight on a particular programming language. Last month Graham started his piece about Java with the following words:

Let me start with an admission: it took me weeks to work out what to talk about for the Java issue of De Programmatica Ipsum. There is just so much to it.

I must start this article of mine about Smalltalk with a similar disclaimer. It took me weeks to work out what to talk about for the Smalltalk issue of De Programmatica Ipsum. I just did not know anything about it.

I treated this situation just like what it was: I had to learn an unknown programming language with a hard deadline. I came up with an idea: I decided to rewrite one of my hobby projects with it. This article will outline the steps I followed as an absolute beginner, the sources of information that helped, and how I ended up with my first working application written in Smalltalk.

TL;DR: Smalltalk is one of the most fertile, passionate, and groundbreaking galaxies of the programming universe I have seen so far.

Choosing A Distribution

The first decision I needed to take was, which dialect of Smalltalk to use? There are quite a few to choose from, actually; the most common choices would have been Squeak (interestingly, itself written in Smalltalk) or Pharo, the latter recommended by Graham. But it turns out there is a lot more, both free (as in beer), free (as in libre), and commercial implementations: VA Smalltalk, Dolphin Smalltalk, VisualWorks, Cuis, GemStone, Cincom, GNU Smalltalk

In my research I found out that Smalltalk had also provided the boilerplate inspiration for new languages and environments such as Newspeak or Amber.

There is also an official Smalltalk source code versioning tool called Monticello, including a Monticello-to-Git migration tool. Of course, we can find the corresponding hosting services: SqueakSource and SqueakSource3, the latter replacing a deprecated SmalltalkHub.

Seaside and Zinc can help developers to create web applications with Smalltalk. You can then build a Docker image and deploy it to a Kubernetes cluster, because that is how DevOps with Smalltalk is done.

But I ended up not following Graham’s advice, and I just sudo apt install gnu-smalltalk. Much to the chagrin of Smalltalk experts reading this, and as much as I found the concept of Smalltalk images fascinating, I was interested in what Simon Lewis called “the first kind” of Smalltalk knowledge in his introduction to “The Art and Science of Smalltalk” (Prentice Hall, 1995, freely available):

First, there is basic knowledge about the language, its fundamental concepts, and core classes.

GNU Smalltalk turned out to be the perfect dialect for this first contact with Smalltalk, offering a very traditional command-line experience. And Vim provided the syntax highlighting I needed to write those initial lines of code.

The Language

First there are the familiar aspects. In that respect, I guess I have cheated, for I felt my previous knowledge of Ruby and Objective-C definitely helped me in those first steps. This is no surprise, knowing that both share a lot of commonalities with Smalltalk. This is even more obvious in the case of Objective-C, where one cannot miss the uncanny ressemblance in class and method names available in Cocoa and GNUStep. Just take a look at the names of methods in GNU Smalltalk’s Object class if you are not convinced.

Then there are the cute aspects; the most prominent of which are the code documentation comments written in the first person. Hence, for the aforementioned Object class:

I am the root of the Smalltalk class system. All classes in the system are subclasses of me.

Then there’s the programming experience itself. Using Smalltalk brings a feeling of absolute freedom, as only a pure dynamic medium can provide. Errors happen at runtime; just like in the case of Objective-C, the compiler does not really check anything for you. The syntax of the language is absolutely minimalistic. This can also be a problem: forget a period at the end of a line somewhere in your code, and it will compile, but will crash with quite an enigmatic error message. Been there, done that.

How to approach the syntax, by the way? I came up with a very simple mind map: where there is a period, think semicolon. Where there is a square bracket, think curly bracket. Where there is a caret (^) think return. The periods at the end made me think of COBOL. Arrays indexes start with 1, which brings BASIC to mind. And the choice of comparison (=) and assignment (:=) operators reminded me of Pascal and ALGOL. It is July 9th, 1973 all over again.

But even though the language carries these memories of yesteryear, Smalltalk feels tremendously modern: there are lambdas, exceptions, garbage collection, overridable custom operators, a (very) high level library of objects at your disposal, object introspection, all bundled in a language standardized forty years ago. There are even “extension methods” for any class, a concept familiar to any Objective-C, C#, JavaScript, Swift, or Kotlin developer these days.

And then there were surprises. if / else statements? Messages. while loops? Messages. Operators? Messages. Of course! Everything is an object.

In my first contact, Smalltalk felt timeless. Very few rules to learn and a tremendous building of stability and coherence to support my work. Quoting Geoffrey James and his “Tao of Programming“:

A program should follow the “Law of Least Astonishment”. What is this law? It is simply that the program should always respond to the users in the way that least astonishes them.

In about 2 hours I could get the gist of core elements of my Conway application: the Cell class, the Coord class, and a main program putting all together. One of the core elements of my implementation of Conway’s Game of Life uses a dictionary of Coord keys and Cell values; GNU Smalltalk’s Dictionary class worked out of the box as expected; after around 10 hours of work I got the program running exactly as I wanted it to, including unit tests.

In retrospect, the most complex thing to do was figuring out that printPaddedWith:to: is a method on Integer, not on String. These things bite me in other languages too, just like Python gets me every time I want to join an array of strings, and I rediscover that join is a method on the String class, not on the Array class. Anyway.

Finally, I discovered that one can trigger an infinite loop by sending the repeat message to a block, and I found that beautiful. Everything is an object in Smalltalk.

Finding Help Online

As much as I found GNU Smalltalk “traditional” (in the command-line sense of the world), my biggest problem while writing these first lines of Smalltalk was to find help. To put it bluntly, the official help pages are terrible.

I found The Terse Guide to Squeak to be the simplest and most complete cheatsheet I could find, and I found the answers to many issues directly in it. I totally recommend it.

The large amount of different Smalltalk dialects makes it hard to search for resources. Questions in Stack Overflow are usually sparse and not always helpful, but thankfully there are exceptions.

Also, sadly, Smalltalk is not really a “mainstream” programming language these days (by which I understand a language used in industry by large numbers of developers.) At the time of this writing, the language does not appear in the TIOBE ranking page (not even in the “Next 50” list) nor in the PYPL ranking, and appears roughly in the middle of the graph of the RedMonk ranking without further mention. This does not mean that the Smalltalk language is not actually used in industry; I have heard from colleagues that many companies still use it. But of course, this might happen in orders of magnitude less often than with, say, Java.

Papers & Books

Smalltalk is a very important language in the history of programming. I quickly re-read bits and pieces of the story of Smalltalk inside “Dealers of Lightning” by Michael Hiltzik (Harper Business, 2000) which tells the story of Xerox’s Palo Alto Research Center (PARC) where Smalltalk was created. I also re-read Alan Kay’s paper and presentation in Bergin & Gibson’s “History of Programming Languages, Volume 2” (Addison-Wesley Professional, 1996). The latter contains the proceedings of the second History of Programming Languages conference (HOPL II); there is a paper about Smalltalk to be presented in the upcoming HOPL IV conference by Daniel Ingalls.

Oh, and do not forget to read Byte Magazine’s August 1981 edition about Smalltalk, freely available online. It is a hallmark piece.

I found quite a few arrogant perspectives about Smalltalk on the web. I tend to dislike them. Smalltalk as a vehicle of expression does not need such attitude in its community. I would rather stay with Bret Victor’s compilation of documents around Smalltalk; the official list of papers and books in the Squeak documentation website; the complete collection of The Smalltalk Report online; the books about Pharo; a free e-book about GNU Smalltalk; and the list of freely available, out-of-print Smalltalk books compiled by Stéphane Ducasse.

Finally, if you are into standards, you can read the 1997 ANSI Smalltalk Standard, and know more about the future evolution of the language.

Impact

A simple thought came to me while writing this piece: Smalltalk’s greatest contribution to programming were the stellar people that gathered around it. Adele Goldberg, Alan Kay, Daniel Ingalls, Ward Cunningham, Bret Victor, and in my opinion the most important of them all, Kent Beck, the subject of this month’s Library article in this magazine.

The Smalltalk galaxy was at the origin of the Graphical User Interface (GUI), Extreme Programming (XP), Design Patterns, the Agile Manifesto, Unit Testing, wikis, and so much more.

Through direct or indirect influence in the design of Objective-C and the NeXT workstation, Smalltalk begat the World Wide Web, Doom, and even Excel’s pivot table (a concept introduced in a now forgotten spreadsheet called Lotus Improv.) And since Java was strongly influenced by Objective-C, Smalltalk’s legacy amplified even more.

Through its Japanese heir, Ruby, Smalltalk ignited Web 2.0 through Ruby on Rails, and the long list of groundbreaking services built on top of it.

I always knew that one day Smalltalk would replace Java . I just didn’t know it would be called Ruby.

(Kent Beck As cited in: Giles Bowkett (2007) “Smalltalk, Outside The Ivory Tower?”. at Giles Bowkett.blogspot.com July 15, 2007 – source)

In the opinion of this writer, the reason for this impact is clear and simple. Smalltalk embraced, from the beginning, late binding and duck typing as ways to model the world.

Very little in our lives appear to be predetermined by a compiler; things appear to us in different types, and we can dynamically query those things, to know more about them. We can gather objects of different kinds in arbitrarily heterogenous collections. We interact, in this runtime environment we call life, with the various objects that surround us, and with people, always sending and receiving messages.

Smalltalk took the risky bet of late-binding method calls to the extreme; a choice that unfortunately crippled its performance at the beginning, somewhat tarnishing its reputation in certain circles. But it was first and foremost a choice that gifted savant pioneers with a fertile playground to re-imagine our world in a virtual space.

During our conversations around this month’s issue, Graham summarized this impact very simply and effectively:

Smalltalk won the war, even though it lost every battle.

Cover photo by James Beheshti on Unsplash.

Adrian Kosmaczewski is a software consultant and evangelist. He is a published writer, trainer and speaker. He holds a Master's degree from the University of Liverpool.