dark mode light mode Search Menu


Moise Nicu on Flickr

Ever wonder where Scratch got a lot of its ideas? Where programming terms like “object oriented” come from? In this issue’s programming language spotlight, we’re going to answer those questions by learning about Smalltalk, a language from the 1970s that didn’t just influence Scratch but was used to make it. We’re going to learn about some of the history of Smalltalk and how it relates to Scratch, then look a little at modern versions of Smalltalk like Squeak and Pharo.

Scratch, if you’re not already familiar with it, is based around programming sprites. Sprites in Scratch are like little robots. Each sprite has its own code that it runs and code that responds to all sorts of events happen in the program, like the background changing or a sprite being clicked on, as well as messages that can be sent by other sprites.

Meanwhile, in Smalltalk, everything in the program—even things like numbers—are all entities called “objects”. Here, an object is a thing that can have its own code that runs and code that’s able to respond to messages from other objects in the program.

Sounds pretty similar to Scratch, right? There’s some pretty big differences though. In Smalltalk, everything is a message. An if-statement for making decisions is just a message to the Boolean objects true or false. Addition is just a message to a number. Every “function” call, which are “custom blocks” in Scratch, is a message.

This makes messages in Smalltalk far more powerful than messages in Scratch. They’re more flexible and can be used to do almost everything.

Also, in Smalltalk, everything is an object. Everything. This would be like if, in Scratch, you could add code not just to the characters in your game but could change the sprite editor, what blocks do, and even how the basic user interface works. That’s what programming in Smalltalk is like.

Now we’re ready to get started with Squeak and, in particular, a version of Squeak that has fantastic books and documentation written about it: Pharo.

So first navigate to the main Pharo website, download the Pharo installer, and run it. You’ll be presented with a slightly intimidating screen that looks like this:

What it’s asking you to do is pick one of these virtual computers with a ton of pre-built code to load. Pick the one that says something like Pharo (stable) 64bit and red starburst to download and make the “image”. Once it’s downloaded you can click on the image on the right-hand side of the screen and hit the play button.

You should now be looking at a screen that looks like:

If you’re following along, I recommend immediately trying out the ProfStef tutorial. It’s a fantastic interactive tutorial that teaches you both the basics of Smalltalk syntax and how to interact with Pharo in general.

As a bit of a spoiler, part of what’s so different about Pharo/Squeak is that you don’t run whole programs so much as you shape the program interactively, writing and running bits and pieces as you go.

To whit, if you have Pharo open hit Ctrl-o w in order to open a “playground” for running code. Now try typing:

heck := Morph new color: Color blue.
heck openInWorld.

Highlight the code you wrote and then hitting “Ctrl-D” to run it. You should see a little blue rectangle. Now you can do all sorts of things with it.

So type:

heck bounds: ((100@100) corner: (300@300)).
heck color: Color orange.

And “do it” in order to change the color of the object on the screen and move it.

This is obviously just a tiny taste of what programming in Pharo is like, but I recommend digging into the book Pharo By Example in order to really start learning more about programming in Pharo. If you want an example of what games programming looks like in Pharo, check out this video.

It’s a great language and I hope you have fun with it!

Learn More

Programming Games in Pharo