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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Select the “Debug” option. This wil l open a debugger on the error code. Now select the second line<br />

down in the top window. This should start with optimized []. The debugger with this line selected<br />

is illustrated below:<br />

In the top scrollable window of the debugger you see each method whi ch has been executed, in the<br />

window below this, you see the source code relating to the method. In this case you see a “decompiled”<br />

version of the code you wrote in the Workspace displayed. It is decompiled because you typed the<br />

original code into the Workspace rather th<strong>an</strong> into a class. It therefore had no class to refer back to. You<br />

will know decompiled code from original source code for two reasons. Firstly, there will be a comment<br />

telling you that it has been decompiled <strong><strong>an</strong>d</strong> secondly the variables will ha ve names such as t1 <strong><strong>an</strong>d</strong> t2<br />

rather th<strong>an</strong> the variable names you chose.<br />

In the debugger you c<strong>an</strong> identify the point at which the error was caused because it will be<br />

highlighted. That is, the message “show” will be in bold. You c<strong>an</strong> correct the error by ch<strong>an</strong>ging “show”<br />

to “show:”.<br />

You could now fix the problem here (<strong><strong>an</strong>d</strong> when you are debugging methods on actual classes you<br />

may well do so). However, there is no point doing so this time, as this is the decompiled version of your<br />

original. Thus <strong>an</strong>y ch<strong>an</strong>ges you make here will be lost once this run is completed (in addition the item<br />

following show has not been compiled yet <strong><strong>an</strong>d</strong> therefore remains as item where as the temporary<br />

variable at the beginning of the do: statement has been decompiled to t2 - rather t h<strong>an</strong> item). It would<br />

therefore be better to go back to the Workspace <strong><strong>an</strong>d</strong> fix it there.<br />

You should ch<strong>an</strong>ge the show statement to read:<br />

temp do: [:item | Tr<strong>an</strong>script show: item]<br />

Now select all the code <strong><strong>an</strong>d</strong> “do it” again. This time the contents of the set shou ld be printed in the<br />

Tr<strong>an</strong>script.<br />

Notice that the order in which you input the strings may differ from the order in which they are<br />

printed. This is due to the way add: works (why not have a look <strong><strong>an</strong>d</strong> see for yourself).<br />

59

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

Saved successfully!

Ooh no, something went wrong!