Previous Page

Chapter 16
SMALLTALK/V STANDARD WINDOWS

This section describes the special windows which Smalltalk/V provides for application development, maintenance and debugging purposes.

The Class Hierarchy Browser shows you the interrelationship of the classes within Smalltalk/V, and lets you edit the code for each class. The ClassBrowser, like the Hierarchy Browser, gives you the ability to edit methods but focuses on an individual class within the hierarchy. Inspectors let you examine and edit objects. They serve as a low-level debugging aid. The Walkback and Debugger give views of the state of your program at the point of an error. They are Smalltalk-level debugging aids. MethodBrowsers let you browse and edit a list of methods. MessageBrowsers give you a convenient means of examining the selectors which make up a method and then cross reference each selector with all the senders and implementors of that message.

Browsers use indexes to access information. Often the information is organized in a hierarchical manner. A browser is a window consisting of at least two panes, a list pane and a text pane. Selecting from the list displays related information in the text pane. This text may be modified and eventually saved.

Class Hierarchy Browser

The Class Hierarchy Browser lets you examine the interrelationships of the classes within Smalltalk/V and edit their contents.

Opening a Class Hierarchy Browser

Under the File menu, select Browse Classes or press Alt + B to open a Class Hierarchy Browser. The Class Hierarchy Browser is divided into five panes as shown in Figure 16.1.

The class hierarchy list appears in the upper-left pane. In this pane, the names of all of the classes in the system are presented in a hierarchical order. Notice that Object appears first in the list as it is topmost in the hierarchy. All other classes are subclasses of Object and therefore appear indented. Subclasses of first level classes are indented further, and so on.

The variables list is the center pane in the top half of the browser. it appears just below the instance/class radio button set. The variables list pane shows the variable inheritance relationship of the selected class to its superclass(es). The variable inheritance is shown in reverse order with the variables defined in the selected class at the top of the list. The superclass of the selected class is then listed with a dash character prefix and suffix, as in "–– SuperclassName ––". Any grandparent superclasses are then listed, ending with the variables of class Object. The variables within each class are listed in alphabetical order.

Figure 16.1
Class Hierarchy Browser

The method list pane is the pane to the right of the variables list. In this pane, either a list of the Instance methods or a list of the Class methods is presented. If a variable is selected in the variables list pane, the list of methods will be reduced to a subset of methods within the class which reference the selected variable.

The instance/class radio button set above the variables list pane are mutually exclusive, affecting the contents of both the variables and methods list panes. When one of these buttons is selected, the other is deselected. Click on the instance button and the variables and method list panes will show all the instance variables and methods, respectively, of the selected class. Click on the class button and all the class variables and methods, if any, will be listed in the panes.

The Smalltalk code itself is seen in the contents pane which occupies the bottom half of the window. When you select a class in the hierarchy pane, the message which defines the class selected is displayed in this pane. Select a method and its code appears. The contents pane is a text pane providing an easy means to edit class definitions and method source code.

Browsing the Hierarchy

To select a class to browse, move the cursor into the class hierarchy list pane, the top-left pane of the window, and click on a class name. Smalltalk/V displays the class definition in the contents pane and a list of variables and methods implemented by the class in the variables and methods list panes. Use the scroll bar to scroll through the class hierarchy list.

The Classes menu contains functions which permit you to maintain the hierarchy including adding and removing subclasses, updating the hierarchy pane after modifications, opening a Class Browser on a selected class and writing out the definition and methods of a class to a disk file.

The Classes menu items are:

Adding Classes

To add a subclass of a class, first select the class in the hierarchy list pane that will be the superclass of the new class. Pull down the Classes menu and select Add Subclass.... The dialog box shown in Figure 16.2 on the following page pops up with the name of the selected class filled into the Superclass: edit field of the Add a Sub Class dialog.

Figure 16.2
Adding a Subclass

The New Class: edit field asks for the new subclass name and radio buttons let you select the type of subclass you are creating. The subclass type depends upon whether the objects belonging to the class are to contain named instance variables, indexed instance variables, or byte arrays. After you make a choice, the new subclass is built and the class hierarchy list is automatically updated. See also Specifying a New Class in Chapter 13 of this manual.

Defining Classes

To define the instance variables, class variables, and pool dictionaries of a class, you must first select the class in the class hierarchy list pane. Smalltalk/V responds by displaying the current class definition in the contents pane. The definition includes the class's superclass, instance variables, class variables, and pool dictionaries. You change the class definition by editing the text in the contents pane. Then pull down the File menu and select Save. The class definition is updated.

When you change a class definition, you must account for all instances, including existing ones you want to keep, as well as new ones. Smalltalk/V automatically recompiles all of the methods in the class and all of its subclasses. In addition, a message is written on the system change.log file giving the new class definition.

Changes to a class definition take effect immediately so that all future instances of the class will have the new structure. You should therefore be very careful when modifying classes that are used by the Smalltalk/V environment because you are changing the environment. Until you are confident with these procedures, you should define subclasses as opposed to modifying the structure of existing classes.

Removing Instances

When you change a class definition or want to remove a class, you will get a walkback window if instances of the class still remain in the system. You must remove them before proceeding.

For window-related classes, make sure to save all the information you want in the open windows, and execute the following. This closes all open windows and reinitializes the System Transcript:

Notifier reinitialize

If your instances are not window-related, or if some still remain, try the following, but save your image first:

<MyClass> allInstances do: [ :each | each become: String new]

Removing Classes

To remove a class, first select the class to be removed from the hierarchy list pane. Pull down the Classes menu and select Remove Class. The system will prompt you for confirmation.

All of the methods in the class are automatically removed when the class is removed. Smalltalk/V will not let you remove a class if it has subclasses or if there are instances of the class anywhere in the environment. If either of these exists, you will get a Walkback window explaining the problem. Remember that Smalltalk automatically removes (collects as garbage) any object that is not referred to by some other object in the system. To remove all instances of a class, references to instances of the class you want to delete must be changed to refer to something else.

If a reference to a deleted class still exists in the system, this reference will now point to the class deletedClass and will not be purged by the collector. This acts as a safety precaution, but these dummy references can take up image space.

You can send the message allReferences to an object to find out all objects that refer to the receiver object. Assigning to nil the object which refers to an instance of the class you intend to delete will remove the reference problem.

Browsing Methods

The method list pane is the top-right pane of the window. Remember that there are two kinds of methods in a class, instance methods and class methods. The list that appears in the method list pane is determined by whether you select the instance or class button located above the variables list pane.

Select a method by moving the cursor into the methods list pane and clicking on the desired message selector. Smalltalk/V responds by placing the source code for the method which implements the message in the contents pane below. You can move the cursor or scroll the methods list pane and select a different method if you like.

The Methods menu contains eight functions:

The Variables menu works in conjunction with the variables list pane to help narrow the focus of methods displayed in the methods list pane. In classes with a large pool of methods, narrowing the list can be very helpful in quickly finding the method or methods in which you are interested.

The Variables menu contains three items:

The scope of the selection focus of the variables list pane affecting the methods list pane is indicated by the checkmark next to one of the items in the Variables menu. These selections are mutually exclusive, so only one item is checked at any time.

The selected item in the variables list may be deselected by clicking on either of the radio buttons or on a class name in the hierarchy pane.

Adding, Modifying and Removing a Method

To see the source code of a method, move the cursor into the methods list pane and select a message selector. The contents pane is a text pane used for adding and modifying methods. The method list pane is used to remove methods from the selected class.

All of the functions on the contents pane menu behave exactly as described under Text Editor in Chapter 15. The method list pane behaves as described under Panes and Scrolling in Chapter 15.

To add a new method,click the appropriate radio button, instance or class, and then select New Method from the Methods menu. The kind of method you create is determined by whether you have currently selected the instance or class button. Your menu selection results in an editable template appearing in the contents text pane. Select and type over the placeholder template items to create a properly formatted new method. Use the Save function from the File menu to invoke the compiler and install the new method.

To modify an existing method, you must first select it in the method list pane. Edit the source code in this pane. After editing the source text, select Save from the File menu to invoke the compiler and install the changed method in the environment.

If a compilation error is detected during the addition or modification of a method, you will see a message in your source code at the point where the error was detected. The error message is selected (reversed). Press Backspace to delete the message, then re-edit the text and use the Save function again to recompile.

When the method is successfully compiled with no errors, Smalltalk/V automatically installs it into the class and all future invocations of this method use this new version. The source code of the new or modified method is written to the change.log file.

You can edit the text of any existing method in the class. The name of the new method is taken from the first line of the text. So if you change the selector name and save it, a new method is created while leaving the original method intact. This is extremely useful when creating variations on a method within a class.

To remove an existing method from the selected class, select the method's selector in the methods list pane and choose Remove from the Methods menu. The method list is immediately updated to verify that the selected method has been deleted from the class.

Class Browser

A Class Browser can be opened in either of two ways. You can send the message edit to any class or you can select Browse from the Classes menu of the Class Hierarchy Browser.

Move the cursor into any text pane. Type in the name of the class you want to browse followed by edit and select it. Pull down the Smalltalk menu and select Do it. This opens a Class Browser for the class.

Figure 16.3 shows a Class Browser opened on the class GraphicsDemo. Class Browsers have three panes: the dictionaryList pane, the dictionaryList pane, and the contents pane.

The title of a Class Browser identifies the class you are browsing. In this window, only the methods for the selected class can be browsed, added or modified.

The dictionary list pane is the top-left pane that contains the two choices: class and instance. If you select class, then the list of class methods is displayed in the method list pane immediately below this pane. If you select instance, then the list of instance methods is displayed in the method list pane.

The method list pane is below the dictionary list pane. It displays the list of class or instance methods implemented by the class depending on whether you select the class or instance item in the dictionary list pane. Click on a method to display its source code in the contents pane.

Figure 16.3
Class Browser

The contents pane is the large pane to the right of the list panes. It displays source code for the currently selected method. You edit, recompile and add new methods in this text pane.

Browsing Method Lists

The functions on the Methods menu let you remove methods and display the implementors (definers) and the senders (callers) of messages. Note that the Class Browser Methods menu is a subset of the Methods menu described above for the Class Hierarchy Browser. Information discussed above with respect to the Methods menu's Senders, Implementors and Remove items applies to the Class Browser as well.

Modifying and Adding Methods

The contents pane is a text pane that modifies and adds methods to the class being browsed. All these functions behave exactly as described under Text Editor in Chapter 15.

The process of adding and modifying methods is the same as described for the Class Hierarchy Browser.

The Inspector

Figure 16.4 shows an Inspector window. Inspectors are used to examine and change objects in the system. They are a low-level debugging aid.

To open an Inspector, send the message inspect to any object. For example, to open an inspector on the Dictionary, associated with the global variable Display, evaluate the following text:

Dictionary inspect 

Figure 16.4
Inspector Window

Or more easily, select the name of the object you want to inspect in the text of any pane, such as the words "Display Dictionary," and select Inspect It from the Smalltalk menu. This has the same effect as evaluating the statement above and is generally more convenient as you may select a word or words in almost any context and inspect it with this menu selection.

Inspectors have two panes. The list pane on the left is the instance variable list pane. The pane on the right is the instance variable contents pane.

The instance variable list pane shows all of the instance variables of the object being inspected. The first item in the list is always the name self, which is the object being inspected. The named instance variables, if any, are listed next. If the object being inspected has indexed instance variables, then they are listed last with numerical indices.

When you select one of the variables from the list, its current value is displayed in the instance variable contents pane. If you select self, the current value of the inspected object is displayed. If you select the Inspect item in the Inspect menu (or double-click on an instance variable), a new Inspector is opened on the selected instance variable.

The instance variable contents pane is a text pane. You can use relevant items from the File, Edit and Smalltalk menus to invoke its functions. You can use this pane to evaluate any type of expression that you wish. There are two very important features of this pane:

Inspecting Dictionaries

A Dictionary is an object which contains associations between keys and values. The Inspector created for objects which are Dictionaries are special. The Dictionary Inspector has two panes: an instance variable list pane and an instance variable contents pane, just like regular Inspectors. Dictionary Inspectors, however, list the keys in the dictionary in the instance variable list pane, rather than instance variable names and indices. When you choose a key in the pane, the associated value is displayed in the instance variable contents pane. Notice that self is not on the list pane of a Dictionary Inspector and that an additional menu, Dictionary, is added to the menu bar.

The Dictionary menu has three selections:

Debugger Windows

There are two debugger windows: a Walkback window and a Debugger window. A Walkback window pops up automatically when errors are detected. When you need more dictionaryList than provided in the Walkback, you explicitly request a Debugger window by selecting Debug in the Walkback menu of the Walkback window or by clicking the Debug button located in the text pane of the Walkback window.

So you can readily identify these important windows, they have been defined with distinctive background pane colors, red for the Walkback and yellow for the Debugger window.

Walkback Window

You can request a Walkback window by sending the error: message to any object with a string describing the error as argument. For example:

self error:'Index is outside of collection bounds'

Smalltalk/V places a Walkback window on the screen when any of the following occur:

Figure 16.5 shows a Walkback window produced by evaluating the expression in the Transcript window. This expression attempts to access the eighth character in the string 'Hello', an obvious error.

The title of the window describes the error. The text pane of the window contains a method walkback showing the incomplete message sends that led to the error. Each line in the text pane represents a single message send, with the most recent send listed first. On each line, the class of the receiver is given first. if the method used is defined in a superclass of the receiver, the class in which the method is defined appears next in parentheses. The string on the right following '>>' is the message selector.

Sometimes you will see lines of the form:

[ ] in ClassName >> methodName

This indicates that an error occurred during the evaluation of a block in the method methodName of the class CIassName.

Figure 16.5
Walkback Window

Whenever you get a Walkback window, you generally do one of three things:

Debugger Window

The Debugger window gives you an expanded view of the Walkback and allows controlled execution of a process, The window has four panes and five buttons. Figure 16.6 shows a Debugger window.

The top left list pane serves two purposes: presenting a walkback and listing breakpoints. If the Walkback radio button above this pane is pressed, the upper left list pane has the same walkback list that appears in the Walkback window in which you selected Debug to bring up the current Debugger window. When you select a walkback line, the other panes contain related information.

Figure 16.6
Debugger Window

If the Breakpoints radio button is pressed, the upper left list pane contains the class name and method selector for all methods which have breakpoints set. When you select a breakpoint line, the pane below displays the source code for the selected method. Setting a breakpoint in a method causes execution to stop when the method is entered, provided that execution is under control of the Debugger (see the description of the Hop, Skip and Jump buttons below).

The bottom pane displays the source code for the selected method and, if Walkback is selected, the source code for the dictionaryList executing statement is highlighted. This pane also serves as a text editor so you can change the code as you do with the Class Hierarchy Browser. You update a method by selecting the Save item from the File menu. If a selected walkback method is updated in this way, all walkback entries above the bottom-most occurrence of the selected method in the walkback list are discarded, because a method they would dictionaryList to has changed.

The two panes on the top right serve as an inspector for the receiver, arguments and temporary variables of the selected method. The variable name pane on the left of the two inspector panes contains self, representing the receiver, and the names of all arguments and temporary variables. The variable dictionaryList on the right displays the value of the selected variable.

Double-click on an item in the variable name pane to open an inspector window on the object selected in the variable name pane. For example, you can inspect the instance variables of the receiver by double-clicking on self.

Use the relevant items from the File, Edit and Smalltalk menus when editing the variable value pane to the right of the variable name inspector pane. When you select Save from the File menu, the value of the selected variable is changed to contain the results of evaluating the expression in the value pane.

The button bar just below the menu bar of the Debugger window contains three more buttons related to debugging: Hop, Skip and Jump. They are also available on the Go menu. These work as follows:

Method Browser

The Method Browser lets you browse and edit a list of methods. There are four menu-based ways to open a Method Browser. Selecting Senders in one of the various browser or debugger window menus which offer this item (e.g., the Methods menu of the Class Hierarchy Browser) will open a Method Browser on the list of all methods in the system that send the selected message selector. Selecting Implementors in any menus which offers this item will open a Method Browser on the list of all methods that implement the selected message selector. In addition, Local Senders and Local Implementors items in the Methods menu of the Class Hierarchy Browser open Method Browsers with the method list selection limited to the scope of the selected class and its subclasses.

A Method Browser is often referred to as a Senders window or an Implementors window depending on the information displayed (which is determined by the menu choice made to open the browser). Figure 16.7 shows a Method Browser on all senders of the message asArray.

Method Browsers have two panes. The list pane on the top is the method list pane, and the pane on the bottom is the text pane.

The method list pane shows a list of methods identified by class and message selector. When you select a method in the list, the source code for the method is displayed in the text pane.

Figure 16.7
Method Browser

The Methods menu in the menu bar of a Sender or Implementor window has six items:

The text pane lets you view and edit the source code for a selected method. Use the relevant items from the File, Edit and Smalltalk menus when editing methods in this pane. When you save the edited text, the method is recompiled.

Message (Selector) Browser

A Selector Browser is a three pane window which provides a way to identify the complete message for each selector in the method displayed in the browser's text pane. The selectors list pane shows all the selectors of messages sent in the method on which the browser was opened. In addition, a methods list pane provides a convenient way to identify senders and implementors of the selector highlighted in the selectors pane.

Figure 16.8
Message or Selector Browser

A Selector Browser is often referred to as a Messages window since its primary list pane displays the selectors, often referred to as messages, which are found in the method displayed in the text pane of the browser, Sender or Implementor window from which the Messages window was opened.

Click on a selector in the selector list pane and the complete message associated with that selector will be highlighted in the text pane. This can be an extremely helpful feature when trying to identify multi-part messages where arguments are interspersed with components of the selector. In addition, the identification of messages in source code related to a selector can be very instructive to those learning Smalltalk by "exploratory" programming rather than by abstract study.

The Selectors menu has two items:

The Methods menu in the menu bar of a Messages window has the same four items as a Methods Browser (MethodBrowser being the superclass of SelectorBrowser). All information relevant to the Methods menu of the Method Browser applies to the Methods menu of the Message Browser.

Previous Page