This is a follow-up to my post about Smalltalk language basics. Here I’ll talk very generally about the Smalltalk environment — at least what I remember about it. Like my previous post, this is meant to be a lightweight conceptual orientation.
The main thing to get is that the Smalltalk environment is a complete, self-contained universe of objects. The Smalltalk language defines an abstract syntax for creating objects and sending. The Smalltalk environment contains actual objects — things in memory being managed by a running process on your computer — that can interact with each other and that you can interact with.
Here's what happens when you do Smalltalk development:
- You launch the VM (virtual machine), which is a runtime engine that will interpret and execute all your Smalltalk code.
- You load a file called a Smalltalk image, which contains a snapshot of the aforementioned universe of objects.
- Once the image has loaded, you're presented with a UI for writing and executing code.
- Everything you do in that UI, even something as simple as moving a window, has some effect on that "universe of objects": you're either creating, modifying, or destroying one or more objects in that universe.
- Before you quit Smalltalk, those changes are saved to the image file to be reloaded next time. (You need to know that there's actually a separate file called the changes file, but that's an implementation detail for purposes of this discussion.)
A rough analogy would be that the VM is like a game engine and the image is like a massive file containing the state of game play exactly as it was when you left off.
The image contains descriptions of all the objects that existed in the "universe" when the snapshot was taken. When the image is loaded, all those objects are re-instantiated. Since everything in Smalltalk is an object, including windows, this means all the windows that were open when you left off will re-appear right where you left them. If you had a debugger window that had stopped at a breakpoint in some code that was running, that debugger will re-appear in exactly the state it was in previously, and you will be able to resume executing that code as if you'd never quit Smalltalk, since the execution context was yet another object that was saved in the image.
Here are some kinds of windows you can open in the Smalltalk environment:
- Browser. A browser window lets you browse the source code for all the classes that exist in the environment, including not only classes you wrote but also Smalltalk's built-in classes, which are themselves written in Smalltalk. (Classes are objects, so they are reconstituted and added to the environment when the image is loaded, just like all other objects.) Browsers are where you create your own classes.
- Workspace. A workspace window is basically a scratch pad where you can type Smalltalk code and run it.
- Transcript. A transcript is a special kind of workspace. You can write text to the global object named
Transcript, and that text will be written to all transcript windows. You can use this anywhere in your code to print output. For example:
Transcript show: 'About to add two numbers.'; cr. x := 3 + 4. Transcript show: x; cr.
- Inspector. An inspector window displays the internal state of an object — its instance variables. You can open an inspector on any object by sending it an #inspect message (e.g. try this:
3 inspect) or, in some contexts, by right-clicking on it and selecting "inspect it" from the contextual menu.
- Debugger. A debugger window lets you step through running Smalltalk code, examine code being executed, and inspect the objects involved. A handy feature of Smalltalk is that in general you can modify code in the middle of debugging, and the new code will be used without your having to restart the program you were running.
You can open as many of each type of window as you want. You generally open them by right-clicking and selecting from a contextual menu, or by hitting a keyboard shortcut.
Speaking of contextual menus, the last thing I'll mention is some operations that are available anywhere you can select Smalltalk source code. If you right-click one or more statements, the contextual menu will contain a whole bunch of options, of which these are the handiest to start with:
- do it — Executes the selected code.
- print it — Executes the selected code and prints the resulting value immediately after the selected text.
- inspect it — Executes the selected code and opens an inspector on the resulting value.
There are typically keyboard shortcuts for these actions.