1 / 32

David Evans cs.virginia/evans

Lecture 22: Objects. I invented the term Object-Oriented , and I can tell you I did not have C++ in mind. — Alan Kay. David Evans http://www.cs.virginia.edu/evans. CS200: Computer Science University of Virginia Computer Science. Menu. A better counter PS5 Comments Databases

maille
Download Presentation

David Evans cs.virginia/evans

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 22: Objects I invented the term Object-Oriented, and I can tell you I did not have C++ in mind. — Alan Kay David Evans http://www.cs.virginia.edu/evans CS200: Computer Science University of Virginia Computer Science

  2. Menu • A better counter • PS5 Comments • Databases • Programming with Objects CS 200 Spring 2004

  3. nextx from Lecture 17 (define x 0) (define (nextx) (set! x (+ x 1)) x) > (nextx) 1 > (set! x 23) > (next x) 24 global environment + : #<primitive:+> nextx: x : 24 parameters: body: (begin (set! x (+ x 1)) x) CS 200 Spring 2004

  4. A 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? CS 200 Spring 2004

  5. Recall from Lecture 17: Application • Construct a new frame, enclosed in the environment of this procedure • Make places in that frame with the names of each parameter • Put the values of the parameters in those places • Evaluate the body in the new environment CS 200 Spring 2004

  6. A Better Counter (define (make-counter) ((lambda (count) (lambda () (set! count (+ 1 count)) count)) 0)) CS 200 Spring 2004

  7. (define (make-counter) ((lambda (count) (lambda () (set! count (+ 1 count)) count)) 0)) global environment + : #<primitive:+> make-counter: mycount: > (define mycount (make-counter)) > (mycount) 1 > (mycount) 2 > (mycount) 3 0 3 1 2 count : parameters: body: ((lambda … parameters: body: (lambda () (set! count …) CS 200 Spring 2004

  8. An 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)) CS 200 Spring 2004

  9. Using Counter > (define bcounter (make-ocounter)) > (bcounter 'next) > (bcounter 'next) > (bcounter 'next) > (bcounter 'how-many) 3 > (bcounter 'reset) > (bcounter 'how-many) 0 CS 200 Spring 2004

  10. Objects • When we package state and procedures together we have an object • Programming with objects is object-oriented programming CS 200 Spring 2004

  11. PS5 How are commercial databases different from what you implemented for PS5? UVa’s Integrated Systems Project to convert all University information systems to use an Oracle database was originally budgeted for $58.2 Million (starting in 1999). Actual cost is likely to be $100 Million. http://www.virginia.edu/isp/ CS 200 Spring 2004

  12. Real Databases • Atomic Transactions: a transaction may involve many modifications to database tables, but the changes should only happen if the whole transaction happens (e.g., don’t charge the credit card unless the order is sent to the shipping dept) • Security: limit read/write access to tables, entries and fields • Storage: need to efficiently store data on disk, provide backup mechanisms • Scale: to support really big data tables, real databases do lots of clever things CS 200 Spring 2004

  13. How big are big databases? • Microsoft TerraServer • Claimed biggest in 1998 • Aerial photos of entire US (1 meter resolution) CS 200 Spring 2004

  14. Rotunda Amphitheater You are here CS 200 Spring 2004

  15. You are here AFC? Picture from 2 Apr 1994 CS 200 Spring 2004

  16. Big Databases • Microsoft TerraServer • 3.3 Terabytes (claimed biggest in 1998) • 1 Terabyte = 240 Bytes ~ 1 Trillion Bytes • Wal-Mart • 285 Terabytes (2003) • Stanford Linear Accelerator (BaBar) • 500 Terabytes (30 KB per particle collision) CS 200 Spring 2004

  17. How much work? • table-select is (n) where n is the number of entries in the table • Would your table-select work for Wal-Mart? • If 1M entry table takes 1s, how long would it take Wal-Mart to select from 285TB ~ 2 Trillion Entries? 2 000 000s ~ 23 days How do expensive databases perform so much faster? CS 200 Spring 2004

  18. Object-Oriented Programming CS 200 Spring 2004

  19. Simula • 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 together CS 200 Spring 2004

  20. Counter in Simula class counter; integer count; begin procedure reset(); count := 0; end; procedure next(); count := count + 1; end; integer procedure how-many(); how-many := count; end; end CS 200 Spring 2004

  21. XEROX 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 Programming CS 200 Spring 2004

  22. Dynabook, 1972 The best way to predict the future is to invent it. Alan Kay (Just a model) CS 200 Spring 2004

  23. Dynabook 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 pages CS 200 Spring 2004

  24. BYTE Magazine, August 1981 CS 200 Spring 2004

  25. Smalltalk • Everything is an object • Objects communicate by sending and receiving messages • Objects have their own state (which may contain other objects) • How do you do 3 + 4? send the object 3 the message “+ 4” CS 200 Spring 2004

  26. Counter in Smalltalk classname counter instance variable names count new count <- 0 next count <- count + 1 how-many ^ count CS 200 Spring 2004

  27. Counter in Scheme (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)) CS 200 Spring 2004

  28. Counter in Scheme using let (define (make-ocounter) (let ((count 0)) (lambda (message) (if (eq? message 'reset) (set! count 0) (if (eq? message 'next) (set! count (+ 1 count)) (if (eq? message 'how-many) count)))))) CS 200 Spring 2004

  29. Defining ask (ask ObjectMethod) > (ask bcounter 'how-many) 0 > (ask bcounter 'next) > (ask bcounter 'how-many) 1 (define (ask object message) (object message)) CS 200 Spring 2004

  30. Who was the first object-oriented programmer? CS 200 Spring 2004

  31. By the word operation, we mean any process which alters the mutual relation of two or more things, be this relation of what kind it may. This is the most general definition, and would include all subjects in the universe. Again, it might act upon other things besides number, were objects found whose mutual fundamental relations could be expressed by those of the abstract science of operations, and which should be also susceptible of adaptations to the action of the operating notation and mechanism of the engine... Supposing, for instance, that the fundamental relations of pitched sounds in the science of harmony and of musical composition were susceptible of such expression and adaptations, the engine might compose elaborate and scientific pieces of music of any degree of complexity or extent. • Ada, Countess of Lovelace, around 1830 CS 200 Spring 2004

  32. Charge • PS6: • Programming with Objects • Monday: Subtyping CS 200 Spring 2004

More Related