Unformatted text preview:

1David Evanshttp://www.cs.virginia.edu/evansClass 20:ObjectsCS150: Computer ScienceUniversity of VirginiaComputer ScienceI invented the term Object-Oriented, and I can tell you I did not have C++ in mind. — Alan Kay2CS150 Fall 2005: Lecture 20: ObjectsMenu• A better counter• Finishing Fish • Programming with Objects3CS150 Fall 2005: Lecture 20: Objectsnextx from Class 18(define x 0)(define (nextx)(set! x (+ x 1))x)> (nextx)1> (set! x 23)> (next x)24globalenvironment+ : #<primitive:+>nextx: x : 24parameters: body: (begin (set! x (+ x 1)) x)4CS150 Fall 2005: Lecture 20: ObjectsA Better Counter• The place that keeps track of the count would be part of the counter, not part of the global environment• Can we do this?5CS150 Fall 2005: Lecture 20: ObjectsApplication1. Construct a new frame, enclosed in the environment of this procedure2. Make places in that frame with the names of each parameter3. Put the values of the parameters in those places4. Evaluate the body in the new environmentRecall from Lecture 19:6CS150 Fall 2005: Lecture 20: ObjectsA Better Counter(define (make-counter)((lambda (count)(lambda ()(set! count (+ 1 count))count))0))27CS150 Fall 2005: Lecture 20: Objects> (define mycount(make-counter))> (mycount)1> (mycount)2> (mycount)3globalenvironment+ : #<primitive:+>make-counter: parameters: body: ((lambda …count : 0(define (make-counter)((lambda (count)(lambda ()(set! count (+ 1 count))count))0))mycount: parameters: body: (lambda () (set! count …)1238CS150 Fall 2005: Lecture 20: ObjectsAn Even Better Counter(define (make-ocounter)((lambda (count)(lambda (message)(if (eq? message 'reset) (set! count 0)(if (eq? message 'next) (set! count (+ 1 count))(if (eq? message 'how-many)count)))))0))9CS150 Fall 2005: Lecture 20: ObjectsUsing Counter> (define bcounter (make-ocounter))> (bcounter 'next)> (bcounter 'next)> (bcounter 'next)> (bcounter 'how-many)3> (bcounter 'reset)> (bcounter 'how-many)010CS150 Fall 2005: Lecture 20: ObjectsObjects• When we package state and procedures together we have an object• Programming with objects is object-oriented programming11CS150 Fall 2005: Lecture 20: ObjectsFinishing Fish12CS150 Fall 2005: Lecture 20: ObjectsRecap (through class 17)• May 1941: Nazis start using Lorenz cipher to communicate between conquered European capitals– Allies know Baudot code, 2 sets of 5 wheels from test messages• August 1941: Operator retransmits message (with abbreviations)– Allies learn one 4000-character key by XORingintercepted messages and then guessing possible plaintexts to find a pair that makes sense• ~Feb 1942: Bill Tutte determines structure of Lorenz machine by analyzing key313CS150 Fall 2005: Lecture 20: ObjectsDouble Delta• Combine two channels:∆ Z1,i XOR ∆ Z2,I =∆ M1,i XOR ∆ M2,iXOR ∆ X1,i XOR ∆ X2,i XOR ∆ S1,i XOR ∆ S2,i= ½ (key)> ½> ½Message is in German, more likely following letter is a repetition than randomS-wheels only turn some of the time (when M-wheel is 1)Prob[∆ Z1,i XOR ∆ Z2,i XOR ∆ X1,iXOR ∆ X2,i = 0] = 0.55So, if guess of initial configuration is correct, generated X will have this property and we will see more 0s than 1s14CS150 Fall 2005: Lecture 20: ObjectsUsing the Advantage• If the guess of X is correct, should see higher than ½ of the double deltas are 0• Try guessing different configurations to find highest number of 0 double deltas• Problem:# of double delta operations to try one config= length of Z * length of X= for 10,000 letter message = 12 M for each setting * 7 XOR per double delta = 89 M XOR operations 15CS150 Fall 2005: Lecture 20: ObjectsHeath Robinson• Dec 1942: Decide to build a machine to do these XORsquickly, due June 1943• Apr 1943: first Heath Robinson machine is delivered!• Intercepted ciphertext on tape: – 2000 characters per second (12 miles per hour)– Needed to perform 7 XOR operations each ½ msHeath Robinson, British Cartoonist (1872-1944)16CS150 Fall 2005: Lecture 20: ObjectsColossus• Heath Robinson machines were too slow• Colossus designed and first built in Jan 1944• Replaced keytext tape loop with electronic keytext generator• Speed up ciphertext tape:– 5,000 chars per second = 30 mph – Perform 5 double deltas simultaneously – Speedup = 2.5X for faster tape * 5X for parallelism 17CS150 Fall 2005: Lecture 20: ObjectsColossus DesignElectronic KeytextGeneratorLogic Tape ReaderCounterPosition CounterPrinterCiphertext Tape18CS150 Fall 2005: Lecture 20: ObjectsColossus• 10 Colossi machinesoperating by end of WWII• Decoded messages (63M letters total) that enabled Allies to know German troop locations to plan D-Day• Destroyed after war, kept secret until 1970s, documents released in late 90s419CS150 Fall 2005: Lecture 20: ObjectsObject-Oriented Programming20CS150 Fall 2005: Lecture 20: ObjectsSimula• Considered the first “object-oriented”programming language• Language designed for simulation by Kristen Nygaard and Ole-Johan Dahl (Norway, 1962)• Had special syntax for defining classes that packages state and procedures together21CS150 Fall 2005: Lecture 20: ObjectsCounter in Simulaclass counter; integer count;beginprocedure reset(); count := 0; end;procedure next(); count := count + 1; end;integer procedure how-many();how-many := count; end;end22CS150 Fall 2005: Lecture 20: ObjectsXEROX Palo Alto Research Center (PARC)1970s:• Bitmapped display• Graphical User Interface – Steve Jobs paid $1M to visit and PARC, and returned to make Apple Lisa/Mac• Ethernet• First personal computer (Alto)• PostScript Printers• Object-Oriented Programming23CS150 Fall 2005: Lecture 20: ObjectsDynabook, 1972(Just a model)“Don’t worry about what anybody else is going to do…The best way to predict the future is to invent it. Really smart people with reasonable funding can do just about anything that doesn't violate too many of Newton's Laws!”— Alan Kay, 197124CS150 Fall 2005: Lecture 20: ObjectsDynabook 1972• Tablet computer• Intended as tool for learning• Kay wanted children to be able to program it also• Hallway argument, Kay claims you could define “the most powerful language in the world in a page of code”• Proof: Smalltalk – Scheme is as powerful, but takes two pages525CS150 Fall 2005: Lecture 20: ObjectsBYTE Magazine, August 198126CS150 Fall 2005: Lecture 20: ObjectsSmalltalk• Everything is an object• Objects communicate by sending and receiving messages• Objects have their own


View Full Document

UVA CS 150 - Objects

Documents in this Course
Load more
Download Objects
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Objects and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Objects 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?