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

Joseph Goodfellow

About me


CoWeb Assignment 1 (Summer 2006 CoWeb Assignment 1)


CoWeb Assignment 2 (Summer 2006 Midterm Review)

The following Smalltalk statements are written in a Squeak Workspace. In order from top to bottom, you execute each statement with Alt-p to print its result. Next to each statement, write the result.

1 + 2 * 3 - 4 factorial   -15

a := #(1 2 3 4 5)    #(1 2 3 4 5)

a select: [:i | i odd]    #(1 3 5)

b := a    #(1 2 3 4 5)

a := a reversed    #(5 4 3 2 1)

b collect: [:i | i * i]    #(1 4 9 16 25)

a perform: #at: withArguments: #(4)    2



A palindrome is a word or phrase that has the property of reading the same in either direction (ignoring punctuation, spaces, and capitalization). So, for instance, a palindrome newspaper headline when the Red Sox finally won the World Series might have read, "Boston did not sob" Write the Smalltalk method to determine whether a String is a palindrome. This code should not just function properly, but use good object-oriented style. To that end, be sure to identify the class in which the method is implemented and whether it is an instance or a class method. (Hint: Characters respond to the message isAlphabetic.)

This method should be implemented in the String class as an instance method.

isPalindrome
     "compare self without spaces and punction in all lowercase with
     self (in same state) but reversed, and return the boolean result"
     ^( ((self asLowercase) onlyLetters) sameAs: (((self asLowercase) onlyLetters) reversed) )



Smalltalk is built on a few uniform design principles. One of these is that computation happens through message passing: An object gets sent a message (perhaps with some arguments) and returns an object. Even traditional control structures (while loops, for loops, if/then/else) are implemented through message passing. For each of the control structures below, translate the Java code into Smalltalk. For each part, indicate what is the object, what is the message, and what are the arguments.

while loop

while (aBooleanTest)
{
     // do stuff
}

In Squeak:

     [aBooleanTest] whileTrue: ["do stuff"].

     object = "[aBooleanTest]".
     message = "whileTrue:".
     arguments = "["do stuff"]".
     (NOTE: the argument is also an object)


for loop

for (i = 1; i <= 10; i++)
{
     // do stuff
}

In Squeak:

     1 to: 10 do: [:i | "do stuff"].

     There are multiple objects, messages, and arguments here.
     objects = "1" and the return value of "1 to: 10".
     messages = "to:" and "do:".
     arguments = "10" and "[:i | "do stuff"]".
     (NOTE: the arguments are also objects)


if/then/else

if (aBooleanTest)
{    // do stuff
}
else
{    // do stuff
}

In Squeak:

     [aBooleanTest] ifTrue: ["do stuff"] ifFalse: ["do stuff"].

     object = "[aBooleanTest]".
     message = "ifTrue:" and "ifFalse:".
     arguments = both "["do stuff"]" blocks.
     (NOTE: the arguments are also objects)



CoWeb Assignment 3 (Summer 2006 Final Exam Review)

Write a Squeak method that contracts a string to a certain size by inserting an ellipsis (...) in the middle of the string. So, contracting ‘I am the Walrus’ to a size of 11 equals ‘I am...lrus’ (4 beginning characters + 3 periods + 4 ending characters = 11 total characters). Your method should deal with special cases, such as when the string is short enough that it doesn’t need to be contracted. This code should not just function properly, but use good object-oriented style. To that end, be sure to identify the class in which the method is implemented and whether it is an instance or a class method.

This class should be implemented in the String class as an instance method.

contractToSize: size
     "contracts self with an ellipsis to 'size' length if greater than 'size'"
     (self size) <= size
          ifTrue: [
               ^ self. "String's contractTo: already does this, but added to indicate method behavior"
          ] ifFalse: [
               ^ (self contractTo: size).
          ].


Reference counting was one of the first implementations of garbage collection. Ultimately, it proved problematic. Why?

It was possible for a circular reference to exist, which equated to two objects pointing to each other but nothing else which will never be garbage collected.

Name two advantages and one disadvantage to using garbage collection.

- Two advantages are, easing the programmers burden of memory management and also, an increase in security and safety (no worries of memory violations or run time core dumps).
- One disadvantage is performance (not as big of an issue anymore, now the biggest problem is control).


Describe in detail how pair programming is done.

- Two people in front of a single computer at the same time.
- Sit side-by-side and slide the mouse and keyboard back and forth.
- The driver types and thinks tactically about the method being created.
- The navigator thinks strategically about how the method fits into the class.

What is the role of pair programming in extreme programming?

- Pair programming increases software quality without impacting the time to deliver a method.
- By trading partners frequently everyone knows about the project as a whole, and the team can thus recover from somebody leaving the team.

What is the role of unit testing in extreme programming?

- All code must have Unit tests and when bugs are found unit tests must be written for those bugs.
- Unit tests should be written before the respective methods they test, to allow the programmer to know when the method is complete (by passing the unit test for that method.)
- Also, completion of unit tests and acceptance tests can be used as a benchmark of the project velocity and anticipated completion time.


Links to this Page