29.11.2014 Views

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

Smalltalk and Object Orientation: an Introduction - Free

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5. A Little <strong>Smalltalk</strong><br />

5.1 <strong>Introduction</strong><br />

In the last chapter we looked at browsers <strong><strong>an</strong>d</strong> the System Tr<strong>an</strong>script, in this chapter we examine<br />

Workspaces <strong><strong>an</strong>d</strong> inspectors. Workspaces <strong><strong>an</strong>d</strong> inspectors are the next most import<strong>an</strong>t tools in the<br />

<strong>Smalltalk</strong> system. We then consider the debugger , one of the most useful tools available to the<br />

developer. Having looked at all the major development tools you will use (at least for the time being)<br />

you are introduced briefly to the <strong>Smalltalk</strong> l<strong>an</strong>guage. You will then use the tools available to write some<br />

<strong>Smalltalk</strong>.<br />

5.2 The Workspace<br />

Workspaces are a kind of direct interface to the system c ompiler. They act a bit like <strong>an</strong> editor in that<br />

you c<strong>an</strong> type <strong>Smalltalk</strong> code into them, <strong><strong>an</strong>d</strong> execute that code immediately. You c<strong>an</strong> define temporary<br />

<strong><strong>an</strong>d</strong> global variables, create inst<strong>an</strong>ces of classes, perform arithmetic calculations et c. The only thing you<br />

c<strong>an</strong>not do is define classes <strong><strong>an</strong>d</strong> methods (that must be done in one of the browsers). In the following<br />

figure, the Workspace is being used to calculate the average of a set of numbers.<br />

To compile code within a Workspace you first select the code using the left mouse button. You then<br />

bring up the Workspace operations menu using the right mouse button (if you have a three mouse button<br />

you will use the middle button). This menu is also illustrated in Figure 5.1. The fourth grouping on the<br />

menu contains do it, print it <strong><strong>an</strong>d</strong> inspect. The do it <strong><strong>an</strong>d</strong> print it operations will compile <strong><strong>an</strong>d</strong> execute<br />

the code. do it will merely run the code, while the print it operation will also prin t the result of<br />

executing the last expression selected. The result is left highlighted so that you c<strong>an</strong> delete it with the<br />

delete key if you no longer require it. Try them out <strong><strong>an</strong>d</strong> see for yourself. The inspect operation will first<br />

compile the code (if requi red) <strong><strong>an</strong>d</strong> then open <strong>an</strong> inspector (see below) on whatever you currently have<br />

selected. It the system was consistent, this option would be called “inspect it”.<br />

You c<strong>an</strong> have as m<strong>an</strong>y Workspaces as you require open, you are not limited to a sin gle Workspace.<br />

Of course on a st<strong><strong>an</strong>d</strong>ard PC or Macintosh screen, you may be limited by space. This highlights <strong>an</strong>other<br />

issue, for developing <strong>Smalltalk</strong> systems, it is often useful to have as much screen “real estate” as you<br />

c<strong>an</strong> get. Bigger really is better in this case.<br />

Figure 5.1: Using the Workspace<br />

53

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!