The Smalltalk system as described above lives in a number of different files. These are shown in the diagram over the page. It is very helpful to have a clear understanding of wliat these different files are, as not only do they hold the system, they hold your programs too.
The virtual machine is an executable program in whatever format your computer supports. As such it lives in its own file, usually called
Chapter 3
The Smalltalk VM, VI, source- code and your code is held in number of files.
oe20 (or st80 if you have an older version of VisualWorks). The
virtual image however, is split between several files of different types.
The most important type of file is the image file. This is a snapshot
in binary form of all the code and data in the virtual image at a
particular time. Because they contain the entire image, image files are
typically several megabytes in size. VisualWorks comes with a standard
'base' image file containing the entire class library and the development environment. This is typically called something like visual. im. When you start VisualWorks, the VM loads the image file into the memory of your computer where it can be worked on. As you program, the image in memory is changing all the time. You can save it
back to a file (using a name to which the system will add . im)
whenever you wish, thus creating your own image file. Because the image file contains everything in the image, i f you restart VisualWorks
using one of your image files you will recreate the entire state of the environment at the time you saved it, including windows open,
programs running, etc. This is a very useful feature. Provided you have
An Introduction to Smalltalk every 30 minutes or whenever you make a serious change), as it is a very convenient way of storing your work.
One thing that is not stored in image files though, is source-code. This applies both to the source of the class library, and the source of your programs. The source-code of the standard class library (in other words, the source-code for the base image file) is held in the sources file. This is a text file (although you wouldn't normally read it yourself), which may be called visual, sources. The system does not load up the entire sources file when it starts. Instead, it goes to it each time it needs to get the source of a particular method for you to look at. The source-code is not needed for the method to run. In fact, the system will run quite happily without the sources file—you just won't be able to browse the code very well.
The source-code for the classes and methods you write is not held in the sources file. Instead, it is held in the changes file. This is a text file which holds all the source-code for all the changes and additions you have made to the image. There is typically one changes file for each image file, usually called <name>.changes (.cha on the PC) where < name > is whatever name you gave to your image file. Together, the sources file and the changes file hold all the source-code for the image.
Just like the sources files, the changes file is not loaded up in its entirety when VisualWorks is started. Instead the system goes to it each time it needs the source-code for one of your methods. Unlike the sources file though, which is never written to, the changes file is written to every time you modify anything in the system. This happens all the time, not just when you save your image. Also, a new version of a method does not overwrite the old version in the changes file. It is simply added onto the end. This means that the changes file is building up a complete history of the changes and additions you've made to the system. VisualWorks provides some tools that allow you to use this to recover from crashes or revert to previous versions of your code.
The final kind of file that is of interest to us here is the file-in file. We've mentioned that it's possible to save your work by saving the entire image in an image file. This is a very convenient way of creating a snapshot of the entire state of the system, but not a very convenient way of saving smaller pieces of code, perhaps to give to someone else. To cater for this, VisualWorks provides a file-out mechanism which will write out just the code you ask for to a separate file. The resulting file can be filed-in to another image. File-ins are text-files holding Smalltalk source-code, although you would not normally edit them outside the VisualWorks system. You can use file-ins to share code
amongst several developers. They are also very important if you need to rebuild your image from the base image—something which can happen if your image becomes corrupted. It is a very good idea to file- out your code regularly (whenever it is in a stable state), as well as saving your image.
Smalltalk is a self-contained system consisting of a language, a class library and a development environment. These three things are all contained in something called a virtual image, which runs on top of the Smalltalk virtual machine, which in turn is an executable program running on your computer. The whole virtual image can be saved in a file and restored later. Your code lives inside the image, or in file-in files you create.
Programming in Smalltalk consists of using the Smalltalk language and development environment to extend the class library to make it do the things you want it to do. We'll come to that very soon. The next step is to look at the specifics of the Smalltalk language.