In this series of articles, I will highlight the advantages of using Squeak/Smalltalk to develop educational software. At some point and based on my experience, I will compare with other development languages. The focus of this article is for educators and developers interested in software programming education applications. In these articles, don't expect to learn about Smalltalk/Squeak programming, my goal is simply to give an overall picture, based on real experience. Feedback is of course very welcome.
In this article I will discuss the Smalltalk/Squeak IDE.
previous article - next article
The most significant developer tools are the class browser, the inspector, the workspace, the debugger, Monticello, Change set sorter (we will not discuss the later one). These are the most used tools, other tools as the transcript, the method finder are pretty useful as well.
Monticello is the default tool to work collaboratively on code development:
- to share code in a centralized repository. http://www.squeaksource.com offers, as does Sourceforge, space to publish and to share code with Monticello
- to handle conflicts and to merge code
- to review code changes
More information can be found at Squeak wiki.
In the following we will show how to load the DrGeoII code from the squeaksource.com repository.
First, open Monticello from
open->Monticello browser in the World menu. Then click on
+Repository button and choose
HTTP, there are several supported protocols to share code.
Write in the new small dialog box:
You can also get the magic strings from the web DrGeo II squeaksource interface.
In the left of the main Monticello window you have the loaded packages. When a package is prefixed with a * it has been modified in the image, and eventually changes can be saved in the repository, if you are granted write access to the repository (if not you can save it locally).
In the right are the used repositories. A repository may contain several source packages.
I invite you to explore the Monticello interface and the link to the Monticello Squeak wiki page. Beware to not commit code change to an open repository.
The workspace is the play field of the Smalltalk developer. From there you can execute code snippets. We continue our exploration of the development tool using DrGeoII code as an example.
Open a workspace from
open->Workspace and write the following code:
canvas := DrGeo sample.
canvas view inspect.
Execute all of it with
Two windows pop up, one is a DrGeoII canvas (without icons, but only a contextual menu in the background) and the other one is an Inspector opened on the object referenced by
canvas view. This one is a view description of the DrGeoII canvas.
The canvas can be deleted with the close handle in the halo. Depending on your Squeak version, the halo handles may appear with right click (this is what I get with Squeak 3.9.1 in GNU/Linux).
Now, create a free point on the canvas (you need to click on the canvas background to open the construction menu).
An inspector presents the state of an instance, it shows its attributes and its values. From the inspector you can view but also edit the attributes of the instance. In the screen shot below, an inspector is opened on the view instance of the DrGeoII canvas. In this view instance, the costumes attribute is a collection of costume objects.
In DrGeoII, a costume is an intermediate object between a geometric model and its Morphic view.
In the inspector, in the large area in the bottom you can type in code snippet to manipulate the attribute, both in read and write mode. Let's suppose we want to inspect the first costume from the costumes collection. Type in the bottom area
costumes first inspect, select it and do a Alt+a. This will open an inspector on the selected instance variable. The title bar of this new inspector should be DrGPointCostume. (you can also execute
costumes first with Alt+i to open an inspector on the value returned by the executed code).
Now let's consider we want to edit the costume and change the name printed in the canvas. We will show how we can do this from our inspector.
As we don't know the costume interface, we can, from the inspected instance variable, ask for the instance class definition. To do so, select the
self attribute in the inspector and do a Alt+b. The browser presents the class of the costume: its instance variables and instance methods.
It is also necessary to know about the ancestor of the costume class. To do so we invoke a special class browser, the hierarchy browser: from the class browser click on the hierarchy browser button.
When exploring the hierarchy, we see the
textMorph: method. We will use this method to send a message to the point costume to change its name.
From our inspector, we can send messages to the object itself with
self as the receiver:
self textMorph: 'my point'. Select this code snippet and execute it with Alt+d:
Now let's introduce a bug somewhere, in the point costume class. We will introduce a bug while we have living instances from our DrGeoII canvas.
Debugging with Smalltalk
From the hierarchy browser we previously opened, we introduce an error in a regularly called method when the canvas is updated. To do so we modify the
DrGPointCostume>>redraw method, as you can expect it, a redraw message is sent to the point costume instances each time the canvas need update. Our introduced bug is just an additional
1/0 instruction in the method code.
Now when we update our DrGeoII canvas (by dragging a point), a
ZeroDivide exception is raised. Within Smalltalk we can catch such exception with the
on:do message sent to a block of code:
do: ["my exception code"]
If we do not handle the exception, Smalltalk handles it and open the debugger directly on the method where the error occurred.
In our example, after you drag a point, several debugger windows are opened. Don't worry, our drag just raised several update events. Close all but one debugger window.
The debugger window shows several informational items:
- the window title is the name of the raised exception
- the execution stack, one call per line
In the execution stack we see the exception was raised in the
SmallInteger>>/ method. However it is not an effective place to look, as we are looking for error in our DrGeoII code. In the previous call instruction from the stack, we recognize our method
DrGPointCostume>>redraw, it is a more interesting place to review. Clicking this instruction call expand the debugger with the method source code.
From there we can edit the faulty source code, save it with Alt+s, then proceed (click on the Proceed button), and that's all.
In this article, we introduced several developer tools:
- Monticello, for collaborative development
- Workspace, to test code snippet and to instantiate objects
- Inspector, to review and modify instance attributes
- Code browsers to navigate within the source code and to edit it
- Debugger, to jump into source code and to fix the error.
We have shown how from one tool, we can jump to another one with still the same application instance. In our developer session demonstration, we never need to destroy our application instance to test modifications in our code. Indeed developing Smalltalk application is a smooth process most of the time, involving small progressive steps: when we introduced our bug, we did not need to restart our DrGeoII application, the same is true when we fix that same bug from the debugger.
In this overview, many aspects and tools were not considered. I invite you to test more by yourself and if necessary to ask questions in the Squeak mailing list.