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

Moctar Diallo

COWEB ASSIGNMENT 3

1.History of Object-Oriented Programming (1 Point)

Ward Cunningham :
Ward Cunningham is well known for his contributions to the developing practice of object-oriented programming, and considered as one of the pioneers in patterns and Extreme Programming. He is also best known as the inventor of the first wiki, which is called WikiWikiWeb. Ward Cunningham is well-known for a few widely disseminated ideas which he originated and developed. Among these, the most famous are the wiki and many patterns in the field of software patterns, including the collection of patterns that later became known as "Extreme Programming" or "XP."
Cunningham is also well known for his contributions to the developing practice of object-oriented programming: in particular, the use of pattern languages, and CRC (Class-Responsibility-Collaboration) cards.

Ivan Sutherland :
Ivan Sutherland was the inventor of Sketchpad, an innovative program that influenced alternative forms of interaction with computers in 1963 in the course of his PhD thesis. It helped change the way people interact with computers. Sketchpad is considered to be the ancestor of modern computer-aided drafting (CAD) programs as well as a major breakthrough in the development of computer graphics in general. Ivan Sutherland demonstrated with it that computer graphics could be utilized for both artistic and technical purposes in addition to showing a novel method of human-computer interaction.

Blocks in Virtual Machines (2 Points)

(Part A) The first two expressions use the message
parenthesisGreaterThan:which does not use a block to separate the two logical parts of the expression. Therefore, before the & message is parsed, both the receiver

(self > greaterThan)

and the argument

(self lessThan)are evaluated.

So even if the first check would fail, the second one is still evaluated, so the same amount of time would be taken in either case.

In the case of the second two expressions,
blockGreaterThan:is used, which uses a block to store the second part of the logical and. In this case, only if the first check fails will the block be evaluated to see the second check. So in the case of the third expression, -500 < 0, so the block is never evaluated; in the fourth expression, 500 > 0, so the block is evaluated. The evaluation of the block is why the two expressions differ in runtime.

(Part B) The block bytecode uses at most two messages to the numbers (one < message and one > message), and it also quits as soon as it has figured out that the logical and of the two expressions must necessarily be false; meanwhile, the parenthesis bytecode uses three messages (one <, one >, and one &) to complete its work and it always evaluates both sub-expressions of the logical and, even if the first comes out false.

(Part C) The smalltalk compiler inlines the
and: [block]expression so that the part of the code that handles the message as a whole and the block are intertwined, leading to greater performance


Collection Classes (1 Point)
1. The OrderedCollection and Set are both classes which store a collection of other objects inside of them. An OrderedCollection also allows duplicated objects and stores the elements in random order. This collection is heavily used for variable-size lists that require control over the location of elements in the collection. For example, an OrderedCollection is often used in user interfaces for holding information to be displayed in a list box. This allows information to be added or removed from the list. A Set does not allow duplicate objects. A Set ignores any request that would add a duplicate to the collection. For example, you may decide it is important to check to ensure there are no duplicate customers in the list whenever a new customer object is added.


2. OrderedCollection and Array both store an ordered collection of objects, and both allow random access to these objects; An Array is a fixed-size collection of elements that can be indexed by integer keys that begin at 1 and increase. An Array cannot grow or shrink. The OrderedCollection can be resized to fit additional contents. You would use an OrderedCollection for most purposes; however, the Array is better when you have an upper bound or fixed number on the number of elements you need to hold at once.


3. You use a Dictionary to store a collection of objects, much like the other collection classes discussed so far. A dictionary is like a simple database table. Dictionaries are unordered collections whose elements are accessed by an explicitly assigned external key. Keys are often strings or symbols, but in principle any object can be used as a Dictionary key. Dictionaries keep track of key/value pairs. Each key/value pair is an instance of a class called Association. An instance of Association points to an object that is the key and points to an object that is the value. An element in a dictionary contains a pointer to an instance of Association. There are no restrictions on the elements stored in a Dictionary. Accessing a Dictionary is very fast because it uses a fast hash method to turn any key into a number, then uses that number to decide which "bucket" to put each element into. If a bucket contains more than one element, a quick linear search finds the one that is wanted.





COWEB ASSIGNMENT 2

Most errors in Smalltalk are caused by messages sent to objects which do not understand them.
Smalltalk does not check to see if an object can handle a message until run-time.
A debugger window will appear.

The top area is the message stack, which contains messages from the code you executed,
from the Smalltalk compiler and the run-time system. Messages are displayed in the format:
Class(Superclass)>>message selector
The top line is the last message sent. Each message listed sent (called) the one above it.
To confirm this, type the following code in the workspace and try to run it:

s_'hello'
Transcript show:s.


Selecting a message in the stack causes the corresponding method or workspace code to be
displayed in the Center area.
Select the top line in the message stack. The top message displays system-generated
information on the error (not very useful), as shown below.

Debugger Inspectors
the bottom left area which has "self and all inst var" and the bottom right
which has "thisContext, all temp vars" are inspectors. The inspectors help you trace variable values.
You can also inspect a selected variable or even change its value and accept it.
the bottom left lists the instance variables of the object. What object? The one currently selected
in the message stack, i.e. the object to which the message was sent.
the bottom right lists temporary variables and arguments of the currently selected method.
Select the line below the top line in the message stack. The method or workspace code in
this case which triggered the error occurred is displayed, as shown below.
However, this might not be the fundamental cause of the error.


Uploaded Image: debug.jpg

COWEB ASSIGNMENT 1

fibonacci
"this will Returns the fibonacci number."

"For 0, the Fibonacci number equals 1"
self = 0
ifTrue: [^ 1].
"For 1, the Fibonacci number equals 1"
(self = 1)
ifTrue: [^ 1].

(Self > 1)
ifTrue: [^ (self - 2) fibonacci + (self - 1) Fibonacci].


^ 'value cannot be negative'





Tracing Code

" this declares the variables data and onlyPositiveNumbers."
data onlyPositiveNumbers


"data is an OrderCollection and contains the following
data = {1, 2, 3, -4, -5, 'error', 6, -7, 999, 2}"
data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2).


onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]].


"data will just have positive numbers by selecting them
data = {1, 2, 3, 6, 999, 2}"
data := data select: onlyPositiveNumbers.


"data will have the values up 999 and does not include 999
data = {1, 2, 3, 6}"
data := data copyUpTo: 999. "not including"


" this will compute and print the average of the values contained
in data which is equal to 3."
Transcript show: data average


Links to this Page