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

Asim Ali

Co Web 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.



Writing Code:

(self 0) ifTrue: [self error: 'fib only works on nonnegative numbers.'].
(self 2) ifTrue: [^1].
^(self - 1) fib + (self - 2) fib.

Tracing Code (1 point)

 | data onlyPositiveNumbers | "It declares two temporary variables data, onlyPositiveNumbers"

data := OrderedCollection withAll: #(1 2 3 -4 -5 'error' 6 -7 999 2). " created an ordered collection 
data = {1, 2, 3, -4, -5, 'error', 6, -7, 999, 2}. "Note that the 2 is added only one time even though it is mentioned twice as data can only have one of each object instance."

onlyPositiveNumbers := [:i | (i isKindOf: Number) and: [i positive]]. "The above code create a new block which returns true if the element is a Number and positive"

data := data select: onlyPositiveNumbers."the select statement causes data to contain onlyPositiveNumbers.elements that return true remains in the orderedCollection data. data contains (1, 2, 3, 6, 999)."

data := data copyUpTo: 999. "The above code copies elments from data which are less than 999 and puts into data. At this point data contains (1, 2, 3 6)"

Transcript show: data average  "data average is shown by the transcript. Data evaluate the message average and the 
entire expression is returned to the show message received by Transcript. 
Transcript prints 3, since the sum of the elements in data is 12 and the total number of elements is 4"

Co Web Assignment # 2

Debugger: How do we use the debugger to solve a programming bug?

When a error or a bug comes in the program, the debugger will open. First , click open the debugger window and look at the stack trace .If you keep on clicking on the stack traces you will see where exactly the error occurred in the code. If you know what is wrong in your code, You can edit your code in the debugger also ,but I think its good to use system browser to edit the code instead of using debugger.

Links to this Page