DOC PREVIEW
Berkeley COMPSCI 164 - Lecture 25

This preview shows page 1-2-14-15-29-30 out of 30 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 30 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Languages as a Tool for Software Engineering Piercing the Mysteries of Object-Oriented ProgrammingLecture OutlineProgrammer Productivity is LowVarious proposals for higher productivityHigher Level Languages and ProductivityObject Oriented Programming tries to model the worldReview of Object Oriented Programming IdeasTwo common models for thinking about itLimits of the message modelGeneric functions are another cut through the same programming text Generic functions consist of “all the methods with the same name”CL Generic functions can be generic with respect to each argument’s type* More general types can also be used for defmethod…A clumsy example for CLOSA neater way, declaring slotsEven neater way, declaring initargsSuperclassesMethod combinationImplementation CriteriaGeneral TechniquesA simplified “How to do OO”A more elaborate “How to do OO”Tell is almost the same. Use rgetWe could stop here but..Parent precedence list for multiple inheritanceMake this efficientClasses become more efficientInstances become more efficientObject orientation has many variantsProf. Fateman CS164 Lecture 25 1Languages as a Tool for Software EngineeringPiercing the Mysteries of Object-Oriented ProgrammingLecture 25Prof. Fateman CS164 Lecture 25 2Lecture Outline• What is the relationship of PL and productivity?– Search for the silver bullet– Fads: Systematic, nth Generation, Object Oriented, …– Side issues: batch vs. time-sharing vs. graphic interaction•OO– Message passing vs Generic functions–The CLOS model– ImplementationProf. Fateman CS164 Lecture 25 3Programmer Productivity is LowIf a programmer produces on average only 5-10 lines of correct code per day, and it is irrelevant whether the code is in assembler or C or …. Then the programmer using assembler is less productive.What can we do? What is the silver bullet?Prof. Fateman CS164 Lecture 25 4Various proposals for higher productivityStructured Requirements etcFormal methodsTeam dynamicsHardware and software support (above the language level)TestingRapid turnaroundProf. Fateman CS164 Lecture 25 5Higher Level Languages and ProductivityUse more concise programming languages?Verify correctnessAutomatic test generationFire the below-average programmers?Hire more programmers?(Re-)educate the programmers in mathematics and logic?Genetic engineering: clone the best programmers?Smart pills? ☺BETTER SUPPORT FOR THE SOFTWARE “LIFE CYCLE”maintenanceportabilityChange the PL “paradigm” to model the application so that the translation from real-world to virtual program world is easier.Prof. Fateman CS164 Lecture 25 6Object Oriented Programming tries to model the worldIs this really a language issue? Yes if you are using a language that interferes; No if you can just add these concepts to the language.Lisp supports many forms of language, and at least 4 OO additions have been proposed and implemented (Flavors, Loops, NewFlavors, CLOS).Lisp allows one to use the “meta object protocol” to define variations on its object system.Prof. Fateman CS164 Lecture 25 7Review of Object Oriented Programming IdeasBase some or all of your language about data objects: running this down to the “ground”….An instance or object is a block of memory that can hold some data in slots, and is associated with some class of similar objects. There is a way of finding out the class (es) of any object.Associated with the class is a collection of methods for manipulating objects, referring to their “slots” and other methods. Sometimes classes have data too.Typically there is a class hierarchy, so that an object is a member of a class, but also a member of its “super” class. Methods can also be attached to the super-classes.Objects – Classes – Hierarchy-Inheritance-MethodsProf. Fateman CS164 Lecture 25 8Two common models for thinking about itThe recent first wave was to think of “message passing” … for example, to find the area of an objecttell obj areaIf obj has a method for area, or a superclass has a method, then we “set self:= obj” and then run the method.Extra arguments are possible liketell obj move 10X := 4 + 5 ;; 4 has a + method, aux argument 5. X has a := method.. Etc [this is like Smalltalk)Prof. Fateman CS164 Lecture 25 9Limits of the message modelThis gets pretty boring, since EVERYTHING is tell RECEIVER MESSAGE EXTRA_ARGSSo why not leave out the “tell” and put the “active part” first; all we need is () to put it in lisp syntax:(MESSAGE RECEIVER EXTRA_ARGS)And now you see that the OO message-passing idea says in effect that we are calling a function … which is the meaning of MESSAGE, but that its meaning is modified by its first argument (only). (+ 4 5) is ‘find the + method of 4, apply to 5.’An obvious generalization: we could allow all the arguments to participate in modifying the meaning of MESSAGE, which brings us to the next model: generic functions.Prof. Fateman CS164 Lecture 25 10Generic functions are another cut through the same programming text GROUPED BY METHOD(defmethod area((z rectangle)) ;; length X width..(defmethod area ((z circle)) ;; pi X r^2 (defmethod area ((z triangle)) …..GROUPED BY CLASSclass rectanglemethod area ….class circlemethod area …Prof. Fateman CS164 Lecture 25 11Generic functions consist of “all the methods with the same name”discriminated by argument types(defmethod area ((z rectangle)) ;; length X width..(defmethod area ((z circle)) ;; pi X r^2 (defmethod area ((z triangle)) …..Textually, you could write these defmethods far apart in the program, if you chose to do so.Prof. Fateman CS164 Lecture 25 12CL Generic functions can be generic with respect to each argument’s type* (defmethod add((z rational)(w rational)) …(defmethod add((z doublefloat)(w rational)) …(defmethod add((z rational)(w doublefloat)) …(defmethod add((z interval)(w rational)) …Etc. We could program combinations of rational + interval + complex +float etc.In general we still need to define the types, their slots, theirinheritance*kinds of objects. The Object system mirrors the built-in types in Lisp.Prof. Fateman CS164 Lecture 25 13More general types can also be used for defmethod……This is how inheritance can be used effectively(defmethod add((z number)(w number)) …CLOS will use the MOST SPECIFIC method. Thus if number is a superclass of rational, doublefloat, complex, interval etc. this last method


View Full Document

Berkeley COMPSCI 164 - Lecture 25

Documents in this Course
Lecture 8

Lecture 8

40 pages

Load more
Download Lecture 25
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 Lecture 25 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 Lecture 25 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?