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.

Breakpoints may be placed in a me thod by using the halt breakpoint method. This c<strong>an</strong> be used<br />

with or without arguments. For example:<br />

self halt. or self halt: 'An example breakpoint'.<br />

This form of the halt message is useful if more th<strong>an</strong> one breakpoint exists within the system as it<br />

allows the breakpoint to be identified. For example, the result of executing the above halt message<br />

expression is illustrated in Figure 15.1. Notice that, the dialog is actually entitled “Exception ”. This is<br />

because both error messages <strong><strong>an</strong>d</strong> halts raise a signal which is caught by the exception h<strong><strong>an</strong>d</strong>ler. Notice,<br />

that unlike the result of encountering <strong>an</strong> error message, the user c<strong>an</strong> proceed after evaluating a halt<br />

message.<br />

Figure 15.1: An example breakpoint dialog<br />

When a halt expression is encountered, the message halt is sent to the receiver. The corresponding<br />

method is implemented in <strong>Object</strong> so all objects respond to it. This opens the halt notifier from which<br />

point you c<strong>an</strong> proceed as if the halt had never been encountered, terminate or select the debug option if<br />

you wish to <strong>an</strong>alyze the state of the object when the breakpoint was encountered. If the debug option is<br />

selected then a debugger window is opened on the method currently executing.<br />

Note that just like <strong>an</strong> error message, a halt message c<strong>an</strong> be used <strong>an</strong>ywhere that you would use <strong>an</strong>y<br />

other message expression. You c<strong>an</strong> therefore conditionalize the call to halt:<br />

(x < y)<br />

ifFalse: [self halt].<br />

15.3 File in/file outs<br />

15.3.1 File out<br />

It is possible to file out <strong>an</strong>y group of definitions using the System Browser (or one of its derivatives).<br />

That is, you c<strong>an</strong> save to a file whole class categories, individual classes, whole method protocols or just<br />

individual methods. By doing so you create a file on the host system’s file system, which contains a<br />

plain ASCII definition of the appropriate class, method etc. To save information to file, select the file<br />

out option in the appropriate browser window.<br />

This ASCI I file c<strong>an</strong> be viewed in the same way as <strong>an</strong>y other ASCII file using one of the host<br />

system’s editors / viewers (e.g. EMACS, vi or more on a UNIX system). However, if you do this, you<br />

will notice that some additional characters have been added (these are “!” <strong><strong>an</strong>d</strong> used as delimiters) as<br />

well as extra statements indicating that something is a class comment or a method protocol name etc.<br />

Normally, you would not need to edit this file <strong><strong>an</strong>d</strong> indeed, unless you are sure of what you are doing,<br />

you should not do so.<br />

The purpose of creating “file outs” c<strong>an</strong> be to provide a perm<strong>an</strong>ent storage for your class definitions<br />

etc. or to share those definitions with others. If you have created a definition which is particularly<br />

import<strong>an</strong>t <strong><strong>an</strong>d</strong> which you do not w<strong>an</strong>t to lose at <strong>an</strong>y cost, it is often a good idea to file it. At least then, if<br />

you have a catastrophic failure <strong><strong>an</strong>d</strong> have to create a whole new image on a new platform, you c<strong>an</strong> still<br />

reconstruct your import<strong>an</strong>t work.<br />

Another reason for creating file outs, is that they take up a lo t less space th<strong>an</strong> the system image.<br />

Therefore, if you have a number of sets of definitions which you wish to retain, but not enough space to<br />

123

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

Saved successfully!

Ooh no, something went wrong!