Codementor Events

Getting started with Squeak/Smalltalk

Published Jun 10, 2019Last updated Dec 06, 2019
Getting started with Squeak/Smalltalk

In this article I am going to introduce to you the world of Smalltalk with the help of Squeak/Smalltalk.

According to Wikipedia:

The Squeak programming language is a dialect of Smalltalk. It is object-oriented, class-based, and reflective. It was derived directly from Smalltalk-80 by a group at Apple Computer that included some of the original Smalltalk-80 developers. Wikipedia

It was originally designed by Alan Kay, Dan Ingalls, and Adele Goldberg.

My experience 🧪

Squeak is a very powerful live programming / authoring system. I use it on daily basis as a live programming utility. I can run code directly in a Workspace or create my own classes for later use. I really like the live coding concept of Squeak where you can run code on the fly and modify running programs. This is something unique to this environment 💎.

Excited? Let's start with the basics.

Installation 📦

Download your copy of Squeak from squeak.org

You can install it on Windows, Mac, or Linux.

Basics 🔢

First of all, we have to get familiar with the user interface.

There are three main important objects for programming.

  • Workspace
  • Transcript
  • Browser

squeak.PNG

Workspace is the main code editor, here you can write code and run it. Transcript is the output console. You can use code like Transcript show: 'Hello, World!' to log to the Transcript window. And lastly, Browser or System Browser is the window where you can see a list of system classes or user defined classes. Not only you can view but also modify classes using the Browser window.

Examples ✨

Now you are familiar with the basics, let's look at some useful examples.


Quick Tip 💡: In order to run code just select the code you want to run and press Ctrl + D on Windows and Linux or press Command + D on Mac. You can also select code and choose do it (d) from the context menu.
doit.PNG

Use print it (p) from context menu or Ctrl + P (Command + P from Mac) to print inline output like the screenshot below.
printit.PNG


Display information using Transcript window:

Transcript clear. "Clear the Transcript"
Transcript show: 'Hello, World!'.

st-hello.PNG
Display information using a message box:

UIManager default inform: 'Hello, World!'.

st-hello2.PNG

Arithmetic expressions:

2 + 2. "addition prints 4"
3 - 1. "subtraction prints 2"
3 * 3. "multiplication prints 9"
10 / 2. "division with fractional result prints 5"
100 atRandom. "get a random number"

String functions:

'Hello, World!' asUppercase. "prints 'HELLO, WORLD!'"
'Hello, World!' asLowercase. "prints 'hello, world!'"
'Hello, World!' size. "prints size of string e.g. 13"

Date/Time functions

Date today. "prints current date e.g. 11 June 2019"
Time now. "prints current time e.g. 12:14:36.047836 am"
Time now minute. "prints current minute from time e.g. 15"

Next steps 📈

I hope this was a good introduction to Squeak. I highly recommend the following resources for learning Squeak.

Note: I will be covering more areas in the coming weeks, mostly GUI and graphics. Looking forward to your feedback and questions.

Discover and read more posts from Humayun Shabbir
get started