View this PageEdit this Page (locked)Attachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Bryan Davidson

CoWeb Assignment 3

History of Object-Oriented Programming
     Kent Beck is the creator of Extreme Programming, a method of developing applications. It lays out a daily schedule that programmers should use while in the midst of developing an application. The schedule encourages communication amongst team members, refactoring of designs, and periodic but frequent feedback from the customer. It uses unit testing as a way to test the application as the programmer adds functionality.
     Ward Cunningham is the creator of CRC (Class Responsibility Collaboration) cards. CRC cards are brainstorming tools used when designing an object-oriented piece of software that help the designers choose which classes are necessary to create, and what responsibilities each class should have. By using the cards along with usage scenarios for the project, the designer can see how the classes will interact with one another and can make changes to a class' responsibilities before implementing the design in software.

Garbage Collection
A.     The greatest advantage of garbage collection is that the programmer does not have to worry about memory faults, allocating memory, or deallocating memory. And because the collection occurs in the background, the user usually does not notice anything abnormal caused by garbage collection. A disadvantage of garbage collection is that in some cases it creates additional work that, especially in processing-intensive programs, could slow down the system. Systems that implement automatic garbage collection may also have higher average memory usage than manual garbage collection because memory may not be deallocated as quickly as it could be if managed by the programmer.
B.     Reference counting keeps track of how many references exist to an object. The memory manager is responsible for counting how many references exist to a particular object. As a reference to an object is added, the count is increased. Similarly, as a reference to an object is removed, the count is decreased. Once the count reaches zero, it is safe to delete the object from memory. As an example, a programmer creates two objects, A and B, with references a and b. a points to object A, and b points to object B. At this point, A has one reference and B has one reference. The programmer now makes a point to object B. Now, object B has two references, while object A only has one reference, making object A safe to delete.
C.     The mark and sweep garbage collection algorithm does not reclaim memory as soon as an object is dereferenced. It periodically halts the program, performs the collection, and then allows the program to resume. The garbage collection algorithm begins by first marking each current object. It then performs a sweep through all the objects in memory, reclaiming the memory of objects that have not been marked. At the same time, it clears the marks from the current objects so that the next time garbage is collected, these objects will be candidates for deletion if they are no longer referenced. As an example, a programmer creates two objects, A and B, with references a and b. a points to object A, and b points to object B. At this point, if garbage collection were to occur, both object A and object B are “current” and will be marked, and thus skipped over when reclaiming memory. The programmer now makes a point to object B. If garbage collection were to occur now, only object B would be marked as “current,” and object A would be reclaimed.
D.     Generational scavenging as a garbage collection algorithm operates based on the theory that most objects have a short lifetime, and restricts garbage collection only to newly created objects. It does so by placing objects into “generations,” and allocating each generation a certain amount of memory. Once a generation becomes full, garbage collection is only performed on that generation. After one or more collections, a younger generation will be created into which all new objects will be placed. Any further garbage collection will then only occur within the younger generation. It is necessary, however, to do periodic collections within all generations to get rid of unused objects that exists in older generations.
     The stop-and-copy algorithm solves the problem of memory fragmentation by dividing the memory into two areas: active and inactive. Newly created objects are placed into the active region. Once the active region becomes full, all “current” objects are copied to the inactive area of memory and the active and inactive areas switch roles. Because objects without references are not copied over, the memory the used to occupy is reclaimed.

CoWeb Assignment 2

The Debugger in Squeak is a very powerful and robust tool. When an error occurs while executing your program, a small dialog box will appear and ask you what you would like to do next. Although some may choose to “Proceed” or “Abandon” (all buttons found on the dialog box) in order to debug their program using more primitive techniques such as printing to the Transcript, the best choice is to hit the “Debug” button. This will open up the larger window of the Debugger, as seen below.

     The title bar of the debugger window explains exactly what the error is (in this case, a MessageNotUnderstood error). The box of text immediately below the title bar is the list of all messages that have been sent before the error occurred, the most recent of which appears at the top. The message that caused the error is rarely ever at the top, but it should be somewhere near the top. Clicking on any of these lines brings that specific method into view in the text box below. From here, the programmer can edit the method directly. Oftentimes, however, one cannot immediately know what the cause of the problem is simply by looking at the code. This is where the southernmost portion of the debugger comes in handy. Clicking on any of the lines in the leftmost box will display some values in the box to the right. For example, selecting “self” or “scene” (both variables) will display the value of the variable at that time in the stack. Another useful category to select is “all inst vars,” which will display all the instance variables along with their values at time in the stack.

     The Debugger in Squeak is in part so useful because of its good graphical user interface. The ability to view the stack of messages sent, edit those messages directly, and view variables' values at specific points in the stack all contribute to the usefulness of this tool. So the next time that dialog box pops up when you are coding, do not be so quick to close it – instead, hit the “Debug” button!

CoWeb Assignment 1

Class-Based Inheritance (1 point)
What is a class? What is an instance? How do the two relate? In Smalltalk, what is the difference between class variables and instance variables? In Smalltalk, what is the difference between class and instance methods.

Squeak uses a class-based inheritance system in which everything is an object. Even every class in Squeak is an object, and can be sent different messages than an instance of that class. An instance of a class is what is created when the class is sent the 'new' message – for example, rover := Dog new. There can be many instances of each class at one time, but only one class object will be present throughout the life of the program. In other words, instances of classes and classes themselves are entirely different in Squeak. Each can hold their own methods and variables. Dissimilar to Java, instances of classes in Squeak will not respond to class methods. Instead, they only respond to messages with instance methods. Similarly, each class responds to messages only with class methods. Just the same as methods, instance variables can only be seen by instances of a class and class variables can only be seen by the class itself.

Borrowing an example from the slides, the concept is somewhat easier to understand. Consider the following code:
rover := Dog new.
rover name: ‘Rover’.
brody := rover new.
brody := rover class new.
The third line, where brody is trying to be created, does not make sense. First of all, it just won't work, because rover, an instance of Dog, is being sent a message that the class Dog should only handle. Secondly, when creating a new instance of Dog to become brody, we don't want it to inherit the attributes of rover in the process. By using the fourth line to instantiate brody, we first asks rover what its class is, and then send the class the 'new' message to instantiate a new, clean instance of that class. This makes for good object-oriented design.

Unit Testing (1 point)
What are the setUp and tearDown methods used for in SUnit testing? Give an example of where you would have to use a tearDown method. Though SUnit and JUnit are the same frameworks, they work a bit differently. Explain why they work differently.

When using SUnit, the setUp method is used to create the conditions necessary to test a class. This usually involves setting variables to specific values and perhaps instantiating new classes to interact with the class being tested. The setUp method is run before testing begins in a class. The tearDown method is run after testing of a class has been completed, and is used to restore the Squeak environment to its normal state. For example, if the setUp method required altering a system-wide value, the tearDown method would return that value to its original state. Because SUnit and JUnit are for different languages, there are obviously some differences between the two testing frameworks. For instance, JUnit must be compiled before being run and uses methods for testing. SUnit, on the other hand, does not require compilation before being run, and instead uses messages for testing.

Links to this Page