One-Slide Summary Objectifying and Programming • Real databases, unlike PS5, have many with Objects concerns, such as scalability and atomic transactions. • An object packages state and procedures. • A procedure on an object is called a method . We invoke a method by sending the object a message . • Inheritance allows one object to refine and reuse the behavior of another. This is a good thing. #2 Outline Interlude: PS5 vs. Wild • PS5 vs. the Real World How are commercial databases different • Problem Sets and PS9 from what you implemented for PS5? • An Better “Counter” UVa’s Integrated Systems Project to • Object-Oriented convert all University information Programming systems to use an Oracle database was – Object = State + originally budgeted for $58.2 Million Methods (starting in 1999). Actual cost ended up over $100 Million. • Inheritance http://www.virginia.edu/isp/ #3 #4 Real Databases How big are big databases? • Atomic Transactions: a transaction may involve many • Microsoft TerraServer modifications to database tables, but the changes should only happen if the whole transaction happens (e.g., don’t charge the – Claimed biggest in 1998 credit card unless the order is sent to the shipping dept) – Aerial photos of entire US (1 meter resolution) • Security: limit read/write access to tables, – Let's see an example ... 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 #5 #6
Rotunda Rotunda Big Databases • Microsoft TerraServer – 3.3 Terabytes (claimed biggest in 1998) – 1 Terabyte = 2 40 Bytes ~ 1 Trillion Bytes • Google Maps (possibly bigger?) Amphitheater Amphitheater – Better color ... • Wal-Mart You are here You are here – 285 Terabytes (2003) • Stanford Linear Accelerator (BaBar) – 500 Terabytes (30 KB per particle collision) #7 #8 How much work? How much work? • Suppose we have a huge database. • table-select is in Θ ( n ) where n is the number of entries in the table • table-select is in Θ ( n ) where n is the – Would your table-select work for Wal-Mart? number of entries in the table – If 1M entry table takes 1s, how long would it – Would your table-select work for Wal-Mart? take Wal-Mart to select from 285TB ~ 2 Trillion – If 1M entry table takes 1s, how long would it Entries? 2 000 000s = ~ 23 days take Wal-Mart to select from 285TB ~ 2 Trillion Entries? How do expensive databases perform table-select so much faster? Hint: How did we make sorting faster? #9 #10 Problem Sets after PS5 PS9 Assignment PS6: Programming with Objects Scheme Problem: Make an interesting dynamic web site. • Teams of 1-78 students PS7: Implementing Interpreters • Can be anything you want that: – Involves interesting computation PS8: Dynamic Web Application – Follows University’s use policies (or on Python SQL, external server) HTML, – Complies with ADA Section 508 (accessible) PS9: Project JavaScript Build a new dynamic web application A list of example topics is provided. #11 #12
Liberal Arts Trivia: Biology PS6 PS6 PS6: Programming with Objects • This egg-laying, venomous (from a calcaneus PS7 PS7: Implementing Interpreters spur found on the hind limb), beaver-tailed, otter-footed mammal is perhaps best known for its “nose”, which follows the style of the Super Ambitious PS8: Dynamic Web Application PS9 Project Extra Ambitious Anatidae family of birds. It is native to eastern PS9 Project Australia and Tasmania, and occurs on the Exam 2 Australian 20 cent coin. PS9: Project Build a dynamic web application Default Negotiate with Wes in advance #13 #14 Recall from before: nextx Liberal Arts Trivia: Art History (define x 0) global (define ( nextx ) environment • Name the Spanish surrealist artist who painted (set! x (+ x 1)) + : #<primitive:+> The Persistence of Memory (oil on canvas, x) 1931). nextx: x : 24 > (nextx) 1 > (set! x 23) environment: parameters: () > (next x) body: 24 (begin (set! x (+ x 1)) x) J. Random Luser can come along and change our counter! This is bad. #15 #16 A Better Counter Recall: Application Rule 2: 1. Construct a new environment, whose • The place that keeps track of the parent is the environment to which the count should be part of the counter , environment pointer of the applied not part of the global environment procedure points. 2. Create a place in that frame for each – Can have more than one counter parameter containing the value of the – Counter state is encapsulated : can only corresponding operand expression. be modified by counter procedure 3. Evaluate the body in the new environment. • Can we do this? Result is the value of the application. #17 #18
A Better Counter Sweeter Version (define ( make-counter ) (define ( make-counter ) ((lambda (count) (let ((count 0)) (lambda () (lambda () (set! count (+ 1 count)) (set! count (+ 1 count)) count))) count)) 0)) This is easier to read (syntactic sugar), but means the same thing. The place for count is created because of the let on this slide and the application on the previous slide mean the same thing. Very slick! We “make our own” zero to start off the counter (purple text). #19 #20 (define (make-counter) (define (make-counter) global global ((lambda (count) ((lambda (count) environment environment (lambda () (lambda () (set! count (+ 1 count)) (set! count (+ 1 count)) + : #<primitive:+> + : #<primitive:+> count)) count)) 0)) 0)) make-counter: make-counter: mycount: > (define mycount (make-counter)) environment: environment: parameters: () parameters: () count : 0 body: ((lambda … body: ((lambda … environment: parameters: () body: (lambda () (set! count …) #21 #22 (define (make-counter) (define (make-counter) global global ((lambda (count) ((lambda (count) environment environment (lambda () (lambda () (set! count (+ 1 count)) (set! count (+ 1 count)) + : #<primitive:+> + : #<primitive:+> count)) count)) 0)) 0)) make-counter: make-counter: mycount: mycount: > (define mycount > (define mycount (make-counter)) (make-counter)) environment: environment: > (mycount) > (mycount) parameters: () parameters: () 1 1 count : 1 count : 2 body: ((lambda … body: ((lambda … > (mycount) 2 environment: environment: parameters: () parameters: () body: (lambda () (set! count …) body: (lambda () (set! count …) #23 #24
(define (make-counter) global ((lambda (count) An Even Better Counter environment (lambda () (set! count (+ 1 count)) + : #<primitive:+> In object-oriented programming , (define ( make-counter ) count)) state is encapsulated with methods that operate on that 0)) (let ((count 0)) make-counter: state. Methods are invoked by (lambda (message) mycount: sending messages . > (define mycount (cond ((eq? message ’ reset!) (make-counter)) (set! count 0)) environment: > (mycount) ((eq? message ’ next!) parameters: () 1 count : 3 body: ((lambda … (set! count (+ 1 count))) > (mycount) ((eq? message ’ current) count) 2 > (mycount) (else environment: 3 (error "Unrecognized message")))))) parameters: () body: (lambda () (set! count …) In Scheme, the single quote (as in ' current) just means “I am making up a symbol or a message name.” See the textbook for more info. #25 #26 Using Counter Objects > (define oocounter (make-counter)) An object packages: > (oocounter 'next) > (oocounter 'next) – state (“instance variables”) > (oocounter 'next) – procedures for manipulating > (oocounter 'how-many) and observing that state 3 > (oocounter 'reset) (“methods”) > (oocounter 'how-many) 0 Why is this useful? #27 #28 Problem-Solving Strategies Problem-Solving Strategies • PS1-PS4: Functional Programming • PS6: Object-Oriented Programming – Focused on procedures – Focused on objects : package procedures and state – Break a problem into procedures that can be combined to solve it – Model a problem by dividing it into objects – Lots of problems in real (and imaginary) • PS5: Imperative Programming worlds can be thought of this way – Focused on data – Design data for representing a problem and procedures for updating that data #29 #30
Recommend
More recommend