Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Jacob Bolton - gte189u
Coweb Assignment 2 - Debugger
Almost any programming endeavor will at some point come across a bug, and Squeak is no different. The purpose of this article is to help the reader recognize an error and utilize the debugger to find the root of the problem.
When an error occurs in Squeak, a window similar to the one below will appear.
This is the error window. The title of the window describes the type of error that was encountered. Proceed allows the programmer to try to step through the error and continue processing, and abandon halts program execution. However, the debug button and the list in the window are of greater interest. The list, from top to bottom, is the stack trace of function calls from the most recent down to the first. This is important to the debugging process because it allows the programmer see the different calls leading up to the error and gain a better understanding of the scenarios in which the error occurs. To begin debugging, either click on the debug button or select an item from the stack trace list, and the debugger window will appear (see below).
In the debugger, the stack list is still present, there are some new button for tracing into/through/around the error, editor shows the currently selected function, and some boxes on the bottom display some variable names. When a part of the stack trace is selected, the debugger will bring up the relevant function in the editor and attempt to highlight the spot in the code where the error occurred. If the higlight is missing or lost siomply press the where button to do the highlight again. At this point, the programmer may need to be able to determine the values of variables, and this is where the boxes at the bottom of the window enter the scene. They allow the programmer to select a variable from the list of variables used/available to the current function and see what their current values are. The two boxes to the left are for instance variables and the
two on the right are for temporary variables.
Once the cause of the error is determined the editor allows the programmer to perform the correction immediately (provided the cause is actually withing the scope of the stack trace). If the cause of an error can not directly be determined by tracing through the error stack, the programmer must investigate further into functions that were not listed but do, in fact, affect the outcome. Initialization functions are a good point to start if it is discovered that an instance variable is nil.
The debugger is not a tool that will always immediately give the location and underlying cause of an error, and traditional debugging techniques still apply. However, the debugger definitely facilitates the locating and investigating into a runtime error.
Coweb Assignment 1
- Class-Based Inheritance (1 point)
- What is a class?
A definition of how to build a particular kind of object.
- What is an instance?
A relization of a class (i.e. a thing actually created from a class definition).
- How do the two relate?
An object is an instance of a class. Classes define instances.
- In Smalltalk, what is the difference between class variables and instance variables?
Instance variables are variables individually attached to every instance of a class. Class variables are not often used, but they are specific to the class itself; they are not in the instances of that class.
- In Smalltalk, what is the difference between class and instance methods?
Instance messages are passed to an instance of a class and they are handled by that particular instance according to the class definition. Class messages are passed to the class itself where they are handled; they typically result in an instance of that class (e.g. new).
- Message Passing (1 point)
- What is message passing and how does it fit into the way you program in Smalltalk?
Message passing is similar to calling a method. It's how things get done in Smalltalk.
- How does message passing work together with the class-based inheritance?
Subclasses inherit messages defined in their respective superclasses.
- What are some of the advantages and disadvantages of message passing?
- Advantages: Late binding makes message passing very powerful because it allows any object to attempt to accept any message.
- Disadvantages: Late binding can make it difficult to know if the object you're passing a message to will actually be able to handle it. It also makes for some interesting precedence in longer message chains.
Link to this Page