Previous Page Next Page

Chapter 2
INTRODUCTION TO THE SMALLTALK/V FOR WINDOWS ENVIRONMENT

In this chapter, you will learn how to install Smalltalk/V, start up its environment, write your first Smalltalk "program" and edit and evaluate some of its most basic expressions. By the end of this chapter, you will be familiar enough with Smalltalk/V to run the tutorials which make up the remainder of Part 2 of this book.

As a Microsoft Windows user, you are already familiar with many of the interface techniques we will briefly review in this chapter. If you are not familiar with "mousing," multiple overlapping window behavior and basic text editing in Windows, please take some time to pull out your original documentation or run your on-line training program for a refresher before going further.

If the Smalltalk/V programming environment is new to you, be sure that you understand the ideas in this chapter before going further. You can learn more about the Smalltalk/V operating environment in Part 3. Chapters 15 and 16 provide additional information on many of the topics introduced in this chapter.

Back Up Your Smalltalk/V Master Disk

Before installing Smalltalk/V, make backup copies of the diskettes included in your Smalltalk/V package. Use standard File System procedures to copy each of the disks for archival purposes. Put your original Smalltalk/V disks in a safe place and continue the installation process using a working copy of the appropriate size Smalltalk/V disk.

Read README.TXT

You will find an archive of compressed files on the master disk with special instructions for decompressing the files included. A complete listing of all the files provided with the current version of Smalltalk/V and notes about any new features and further installation procedures are contained in an ASCII text file named README.TXT. Enter the following command at the DOS command prompt:

>a:\VWIN
>type README.TXT

or open the file with any text editor or word processor which reads text files. If you need to review this information again, simply open the README.TXT file like any workspace
file while running Smalltalk/V.

Run the Install Program

To install Smalltalk/V, first bring up Microsoft Windows. Insert Disk 1 into a disk drive (such as A:). Next, select the Run... item from the Program Manager menu. Enter the following command:

a: install

The INSTALL program asks you where you would like to store the Smalltalk/V files. These will be stored in the \VWIN directory, as a default, but you can specify any other directory.

Starting Up Smalltalk/V

Following the instructions in README.TXT, start your installed Smalltalk/V environment like you start up any of your other Microsoft Windows applications. Your fresh, new Smalltalk/V system opens looking like this:

Figure 2.1
Start Up Screen

The Transcript window--we ignore the "Smalltalk/V" title prefix when referring to windows by name--is always present when running Smalltalk/V. This window is a simple text editor pane used primarily for system messages. It stays open the entire time you are running a Smalltalk/V session.

Four interface features are immediately apparent:

The graphical user interface of Microsoft Windows features many more window and system controls than described here. Some of these features are described a little later in this chapter and in the Reference section. For even greater detail about the Windows user interface, see your system documentation.

The Transcript window, like all text pane windows in Smalltalk/V, is easily edited using standard text manipulating conventions. Point the cursor anywhere in the Transcript window and click the left mouse button. The insertion point blinks in the top left corner. Now type:

Hello, Smalltalk/V!

You've made the first, though trivial, change to the state of your Smalltalk/V system.

Exiting Smalltalk/V

To exit Smalltalk,, select Exit Smalltalk/V ... from the pull-down System menu.

Figure 2.2
System Menu Exit Item

You will be prompted with a dialog box which asks whether or not to save your changes. Click the Yes button, or simply press Enter to accept this dialog's default Yes response.

Figure 2.3
Exit Dialog

Smalltalk/V preserves the state of your current Smalltalk/V environment--a kind of "snapshot" of all the existing objects in your current Smalltalk "world," including window placement and contents. This way, when you restart your Smalltalk/V system, you will begin right where you left off.

Saving an Image, since it is a large file, can take some time. That's why you are presented with the Yes, No and Cancel choices in the Save Image? dialog box.

After Smalltalk/V has completely saved its Image, again start up the Smalltalk/V application to continue your orientation. Notice that the Transcript window is where you left it with your greeting intact. (Also note that this manual adopts the graphical convention of the host user interface in screen displays. As host operating systems and graphic user interfaces evolve, elements of the interface are subject to revision and enhancement. The focus of this manual is Smalltalk/V. This focus will eliminate confusion when updating your base operating system.)

Run the Graphics Demo

Now, run the Graphics Demo application. Pull down the File menu on the menu bar and select the Graphics Demo item.

Figure 2.4
Starting the Demo

A new window, Graphics Demo, opens to show off some Smalltalk/V graphics. Click and drag downward in the Graphics menu in this new window's menu bar. Stop on one of the menu items and release the mouse button to see the corresponding graphic drawn in the Graphics Demo window.

Figure 2.5
Running the Demo

Take a minute to run the graphic displays of the Graphics Demo application. You will find a wide range of impressive graphical displays generated by the various menu items under the Graphics, and Animation menus. A color monitor produces the most impressive rendition of these short Smalltalk graphics programs; however, a monochrome monitor works without modification to the Graphics Demo.

Window Basics

A window is an object with a border, a title bar, an menu bar, window control icons, scroll bars and one or more panes. These components are shown in Figure 2.6. A window can be active or non-active. Windows can be opened, closed, resized, zoomed, moved, scrolled and collapsed.

Window movement and scrolling behavior conform to host system conventions:

Figure 2.6
A Window

Window Panes

Each window has one or more panes. Each pane may have its own custom menu or may be associated with one of the standard menus which appear in the window's menu bar. For example, text panes are generally associated with the Edit menu unless a custom menu is assigned by the programmer.

A pane may be a basic text editing space, a "canvas" for graphics or a scrolling list of uneditable items from which you click on an item to make a selection. Each pane may have zero, one or two scroll bars and it may include an insertion point, if it is a text pane.

The Smalltalk/V programming environment makes extensive use of multiple-pane windows to provide powerful views into the storehouse of Smalltalk source code which you will use and modify to create your own applications. A multi-pane window shown in Figure 2.7 provides a rich and flexible user interface to a typical business application.

Figure 2.7
Three-pane Window

A Quick-Tour of Smalltalk/V Special Windows

Part of the enjoyment of programming in Smalltalk/V is that you have a lot of freedom to experiment. To whet your appetite, a Quick Tour of the special purpose windows of the Smalltalk/V environment follows. While these windows are made up of component parts common to the host interface, their special functionality makes them significant "power tools" for developing Smalltalk applications.

You will be introduced to these special windows through a series of exercises in the tutorials which make up this part of the manual. Additional information on Smalltalk/V windows is found in Chapter 16. Here we generally describe the contribution each of these special windows makes to your Smalltalk/V development environment and show a picture of the window in action.

The Transcript Window. The Transcript appears when you first run Smalltalk/V. The Transcript is used by the system for various messages and can be used by the programmer as a convenient editor and code evaluation window for transient information. While it is among the most plain of Smalltalk/V system windows, it is omnipresent--it cannot be closed--although it can be minimized to an icon.

The Class Hierarchy Browser. This multi-paned window shows you the interrelationship among classes and subclasses within Smalltalk/V, and lets you edit their associated variables and methods. The bulk of your application development takes place in this window.

Sender and Implementor Browsers. These windows provide context-sensitive cross references among the multitude of methods within classes of your system's class hierarchy.

Inspector. Examine and edit objects in this metaphorical X-ray machine for seeing the "insides" of Smalltalk objects. Inspectors often serve a low-level debugging function.

Walkback. This window pops up automatically when errors are detected. It gives a view of the state of your application at the very moment it appears. You either dismiss the Walkback and do other things or call up the Debugger to extensively examine and correct the communication problems among your Smalltalk objects.

Debugger. The Debugger gives an expanded view of the Walkback. Its four panes provide a high-level debugging aid to help you correct programming errors. This second most used window for editing code is the most direct means to zero in on and change methods containing errors once you have roughed them out in the Class Hierarchy Browser.

As you become more skilled in the use of these specialized windows, your programming productivity will increase. This dynamic programming environment together with Smalltalk's fully object-oriented language gives you a powerful application development environment.

Menu Basics

There are many menus in the Smalltalk/V environment. A menu is an object containing a list of choices relevant to the Smalltalk system as a whole or to a particular window, pane or other object. Menus are normally dormant, that is unseen except for their name in a window's menu bar. Menu items are presented in pull-down panes which you make visible by clicking a menu's title in the menu bar.

Menus conform to host environment menu conventions:

In addition to conventional pull-down menus in a window's menu bar, Smalltalk/V provides pop-up menus which can be accessed in many panes simply by clicking the right mouse button. These context-sensitive pop-up menus can push your productivity even higher without the need for memorizing keyboard commands.

Quick Reference of Standard Menus

At least three menus are always visible in the menu bar at the top of a Smalltalk/V window: File, Edit and Smalltalk. In addition, the System Menu icon is found to the left of the title bar as in all windows.

The items found in each of the Smalltalk/V standard menus are of wide-ranging applicability throughout the system. As Smalltalk objects, the standard menus can be disabled, expanded or otherwise modified to tailor the Smalltalk/V system to your taste or needs. It is probably best that you don't attempt such alterations until you at least complete the tutorials.

The standard menus will be joined by specialized menus in the menu bar based on the functionality of the window displaying the menu bar. For example, the Classes, Variables and Methods menus appear to the right of the standard menus in the menu bar of a Class Hierarchy Browser window. You will learn about the special features of window specific menus as these windows are introduced in the course of the tutorials.

The items found in each of the Smalltalk/V standard menus are:

The System Menu (Alt + spacebar):

The File Menu (Alt + F):

The Edit Menu (Alt + E):

The Smalltalk Menu (Alt + S):

Text Editing

As a Smalltalk programmer, most of what you do in Smalltalk/V will involve text editing activities inside a window pane. For many of the applications that you write, you will be able to find relevant source code that is already available in Smalltalk/V. You can copy and edit this code to produce new objects and object behaviors that you need. This saves you from having to "re-invent the wheel" each time you want to develop a Smalltalk/V application.

In this section we'll review how to enter and edit text in Smalltalk/V. If you need more information, see Chapter 15.

Text editing in Smalltalk/V conforms to text editing conventions of the host environment. In general, mouse editing techniques use the left mouse button unless otherwise specified:

For maximum user productivity, Microsoft Windows provides a wide range of keyboard commands to perform many of the basic mouse-based interactive functions. Personal preference largely determines which command interaction you will use most often. If you are new to Windows, you may find the mouse interface reduces the memorization required to perform routine interface interactions. With experience, you can incorporate use of the many key combinations of Alt, Control, alphanumeric and function keys available to you for interface interactions.

To keep this manual's descriptive instructions concise, activities will largely be described in terms of mouse-based interaction. As you become familiar with the general host interface, feel free to substitute keyboard-equivalent commands to perform the interactions described throughout this manual.

A Smalltalk/V Shakedown Cruise

Now that you are familiar with the basic interface of Smalltalk/V, it is time to start putting it to work for you.

Tutorial Files

In this and the tutorials that follow, you'll be seeing and using many examples. We've provided these examples for you in several disk files. To save yourself the time and effort of typing in these examples, use the Open... item in the File menu to open and use these files. The example files are organized by chapter in the TUTORIAL directory.

For instance, the examples for this chapter, Chapter 2, are in the file named chapter.2. You can access this file by first selecting Open... in the File menu of an active Smalltalk/V window. Use the Open File dialog scrolling lists to locate the TUTORIAL directory and the chapter.2 file name. Click to select chapter.2 in the left side list pane and click the Open button. The contents of this file will be displayed in a new workspace window.

Of course, personally typing in the examples can enhance your appreciation of Smalltalk syntax and formatting specifics. Typing can also be time consuming. We often give directions in the tutorials which indicate direct entry of example expressions. If you are using the tutorial file on disk, simply locate the example on disk and perform the evaluation as instructed. The examples in the disk file are set up in the same sequence in which they occur in the tutorials.

Evaluating Smalltalk Code

To evaluate a Smalltalk/V expression, enter the code into a window or text pane and select it using any of the text selection techniques reviewed above. Then pull down the Smalltalk menu and select Do It or Show It from the menu. Alteratively, you can press Ctrl + D or Ctrl + S, respectively, to evaluate the expression with or without a text description of the return value resulting from the execution being displayed in the window or pane. You will also find the right button click to bring up the text pane menu convenient as this menu will pop up directly under your cursor with the Do It and Show It items immediately accessible with a quick point and left click.

For example, point anywhere inside the Transcript window and click to bring the insertion point into a convenient location. Type the following expression:

3 + 4

Click and drag to select the entire expression, then evaluate it with Do It. Smalltalk/V executes the expression but shows no results on the screen. Select this expression again and evaluate with Show It. Smalltalk/V both executes the expression and returns the result. The returned result is now the selected text so you can easily delete it after confirming the evaluation.

In the tutorials that follow, you will initially use the Show It method of evaluation most often because it is a convenient way to evaluate elementary expressions and see the result in one step. Eventually, you will use Do It more, as the expressions you evaluate set in motion more elaborate interactions.

Compilation Errors

Type the following expression into a workspace window. Select the entire expression and evaluate it with Do U:

Window turtleWindow: `Turtle Graphics'.
Turtle
home;
north;
black;
   mandela: x2 diameter: 300

The result should be as shown in Figure 2.8 .

Figure 2.8
Compilation Error

The compiler detected an error. The error message is inserted in front of the error and is selected. To delete the error message, press the Backspace key. Now correct the expression by changing the letter x to the number I so that the line reads:

mandela: 12 diameter: 300

Run-time Errors and Walkback Windows

Select the corrected example expression as before and evaluate it. Make sure that you select the entire expression, not just the corrected line. The result should be as seen in Figure 2.9 on the following page.

Smalltalk/V detected a run-time error. In this case, the problem is a misspelled word: mandela should be mandala. The window notifying you of the error is called a Walkback window. Also notice that the evaluation of this expression got further than when the compiler detected an error in the previous example. This run-time error occurred after the Window expression was evaluated, resulting in a new window opening on your display just prior to the Walkback window popping up over top of it.

To correct the error, close the Walkback by selecting Close in the File menu. Also close the Turtle Graphics window. Next, correct the misspelling in the workspace window. Now select and evaluate the entire expression again.

Figure 2.9
Runtime Error

Success! You've just created your first Smalltalk/V code which accessed the graphics Dynamic Link Library. More importantly, you've seen that Smalltalk/V is a "robust" system, detecting various types of programming errors and allowing you to correct them without your having to suffer the frustration of a system crash.

Prompters

Smalltalk uses "prompters" for routine, short interactions between the user and the system or application. Prompters are implemented as "pop-up windows" or dialog boxes.

For example, the code for this prompter asks you to enter your name:

Prompter prompt: 'What is your name?' default: ' '

Enter the above expression in a workspace window and select it. Then evaluate this expression with Show It. The resulting interaction will be as shown in Figure 2.10.

Type your name in response to the prompter and press Enter or click the OK button in the prompter dialog window. Smalltalk closes the dialog and returns your entry as the response to the prompter. You can confirm the interaction by noticing that your answer is returned as the result of your Show It evaluation of the example expression.

Figure 2.10
Prompter

Reusing Smalltalk Code

A very useful and productive feature of Smalltalk/V is that you can edit code that you have previously evaluated and then evaluate the expression again. For example, in the prompter example above, change `What is your name?' to `What is your age?'. Evaluate the expression with Show It. Although this is a trivial example, you will learn in the tutorials how productive you can be by recyclin Smalltalk code.

Browsing Smalltalk Classes and Methods

The Class Hierarchy Browser is your main "viewport" into the vast amounts of Smalltalk code at your disposal, which make up the Smalltalk/V system. Smalltalk is the programming language equivalent of those clear plastic "visible man and woman" models you had as a youngster. With the same ability to whet your curiosity, Smalltalk is not only yours to use but yours to inspect, modify and extend. Select Browse Classes from the File menu. Here's an example of what you will see as you scroll and select in the lists of classes and their methods:

Figure 2.11
Class Hierarchy Browser

The Class Hierarchy Browser uses list panes and a button pane in addition to the already familiar editable text pane. Take a few minutes to experiment with scrolling the Classes, Variables and Methods list panes. Click on various items in each list and notice how the other panes are affected. You will learn how to use this window to explore and modify the Smalltalk/V system throughout the rest of the tutorials.

Your First Smalltalk/V Class, Method and Object

Let's run through a "big picture in a nutshell" example. While trivial, the following procedure is representative of the activity you will perform again and again as a Smalltalk programmer.

A summary of the steps you will take are as follows:

If Smalltalk/V were a conventional programming language, this exercise would be called "My First Program. " But in Smalltalk, programming is an act of extending your environment by creating new instances of objects, defining new types of objects and teaching the objects new methods of behavior. This evolutionary process continues until you have objects whose elaborate combinations of behavior perform the user interaction you would otherwise call your "computer program."

At the end of this exercise you will not have a file on disk- HELLO.C. If you were using the C language, for instance- which you can point to and say, "That's my `Hello, World!' program." Instead, you will have a new class of object, Greeter, that has a salutation method which returns the String, `Hello, World!', and a new global variable object, WelcomeWagon, which you can ask to greet the world. Then by saving the Image, this class, its method and your new WelcomeWagon object will become a permanent addition to your Smalltalk/V environment.

So, let's get going. Follow each of the steps as described, in order. Don't worry if you don't understand the details of what you are doing. The tutorials which follow will introduce, in a series of sessions, the procedure briefly showcased here. To start:

Create a new class, Greeter

Add a Greeter Method, salutation

Create a Global Variable, WelcomeWagon, and Make It Greet the World

   WelcomeWagon:= Greeter new
   WelcomeWagon salutation

That's it. You have completed your first Smalltalk/V application development cycle.

What You've Learned So Far

Congratulations on making your way through this whirlwind tour of the Smalltalk/V environment. Subsequent tutorials will step you through material a bit more slowly so you can explore the Smalltalk/V environment and extend your ideas on your own. So far you have familiarized yourself with the following:

You are now familiar enough with the Smalltalk/V environment to proceed with the remaining tutorials. To review any topics covered in this chapter, you can either repeat the corresponding section of this tutorial or refer to more detailed information in Part 3.

Previous Page Next Page