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

James Poje

History of OOP:Alan Kay: Main developer of SmallTalk
Kent Beck: One of the founders of XP

bCollection Classes:
1. How do OrderedCollection and Set differ?
    OrderedCollections allow identical entries and have an index associated with each entry, while Sets do not have an order and do not have identical entries.
2. How do OrderedCollection and Array differ? Why would you use one over the other?
    An Array has a set length while an OrderedCollection grows as you add items to it. Arrays are useful when you know the exact size of your structure.
3. How do you use a Dictionary? Why is accessing a Dictionary so fast?
    Dictionaries are used by adding an object associated with a key to it. Dictionaries are fast because they hash the keys, vastly reducing the amount of iteration needed to see if an entry exists (and retrieve it).

OO Language Design:
2. C++ and Java are statically typed. Objective-C and Smalltalk are dynamically typed. What are the trade-offs of static and dynamic typing?
    Static typing greatly reduces "type errors" where the method being called does not exist for the object. The trade off comes from ease of development in being able to send any kind of message to an object.
3. Most OO languages run on a virtual machine. Java and Smalltalk do. C++ does not. What are the advantages and disadvantages of using a virtual machine for OO programming?
    A VM allows for garbage collection, error checking, and interactive debugging. However, execution can be significantly faster without a VM's overhead.

Writing Code:
(Yes, it's iterative - recursive fib wastes memory like a beast)
fib: n
	| count temp cur old |

	count := 1.
	cur := 1.
	old := 1.

	(n < 0) ifTrue: [^ -1]. "-1 error code for negative ns"
	(n < 2) ifTrue: [^ 1]. "return 1 for fib(0) and fib(1)"

	[count < n] whileTrue: [
		temp := cur + old.
		old := cur.
		cur := temp.
		count := count + 1.

	^ cur.

Reading Code:
| data onlyPositiveNumbers |
> This declares the local variables data and onlyPositiveNumbers

data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).
> This creates an OrderedCollection object with the listed values inside of it (an OrderedCollection object sorts its objects, as the name entails)
> data: {1 2 3 -4 -5 'error' 6 -7 999 2}

onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].
> This creates the set of Numbers that have positive values

data := data select: onlyPositiveNumbers.
> data now only holds values that are also in the onlyPositiveNumbers collection
> data: {1 2 3 6 999 2}

data := data copyUpTo: 999. "not including"
> This copys all of the values in data into itself excluding those greater than or equal to 999
> data: {1 2 3 6 2}

Transcript show: data average
> This prints the average value of data out on the Transcript

Link to this Page