Lecture 5 Programming Paradigms Dilemma of being a cyborg Story details the move to Digital of many things precious to us music photos videos Is there something lost in the process and what happens when that data is deleted YOUR backup solution ID: 526632
Download Presentation The PPT/PDF document "The Beauty and Joy of Computing" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
The Beauty and Joy of Computing
Lecture #5Programming Paradigms
Dilemma of being a cyborg
Story details the move to Digital of many things precious to us – music, photos, videos. Is there something lost in the process? and what happens when that data is deleted. YOUR backup solution?
UC Berkeley EECSSr Lecturer SOEDan Garcia
http://www.nytimes.com/2012/01/29/magazine/what-happens-when-data-disappears.htmlSlide2
What are they? Most are Hybrids!The Four Primary ones
FunctionalImperativeObject-OrientedOOP Example: Skecthpad DeclarativeTuring CompletenessSummaryProgramming Paradigms LectureSlide3
“The concepts and abstractions used to represent the elements of a program (e.g., objects, functions, variables, constraints, etc.) and the steps that compose a computation (assignation, evaluation, continuations, data flows, etc.).”
Or, a way toclassify the styleof programming.What are Programming Paradigms?en.wikipedia.org/wiki/Programming_paradigmSlide4
This makes it hard to teach to students, because most languages have facets of several paradigms!Called “Multi-paradigm” languages
Scratch too!It’s like giving someone a juice drink (with many fruit in it) and asking to taste just one fruit!Most Languages Are Hybrids!Slide5
Computation is the evaluation of functions
Plugging pipes togetherEach pipe, or function, has exactly 1 outputFunctions can be input!FeaturesNo stateE.g., variable assignments No mutation E.g., changing variable values No side effectsExamples (tho not pure)Scheme, Scratch BYOBFunctional Programming (review)en.wikipedia.org/wiki/Functional_programming
f(x)=(x+3)* x
+
x 3
*
x
f
xSlide6
“Sequential” ProgrammingComputation a series of steps
Assignment allowedSetting variablesMutation allowedChanging variablesLike following a recipe. E.g.,Procedure f(x)ans = xans = ansans = (x+3) * ansreturn ansExamples: (tho not pure)Pascal, C
Imperative Programming
en.wikipedia.org/wiki/Imperative_programmingf(x)=(x+3)* xSlide7
Objects as data structures
With methods you ask of themThese are the behaviorsWith local state, to rememberThese are the attributesClasses & InstancesInstance an example of classE.g., Fluffy is instance of DogInheritance saves codeHierarchical classesE.g., pianist special case of musician, a special case of performerExamples (tho not pure)Java, C++
Object-Oriented Programming (OOP)
en.wikipedia.org/wiki/Object-oriented_programmingwww3.ntu.edu.sg/home/ehchua/programming/java/images/OOP-Objects.gifSlide8
Dr. Ivan Sutherland“Father of Computer Graphics”1988 Turing Award (“Nobel prize” for CS)
Wrote Sketchpad for his foundational 1963 thesis The most impressive software ever writtenFirst…Object-oriented systemGraphical user interfacenon-procedural languageOOP Example : SketchPaden.wikipedia.org/wiki/Sketchpad
Spent the past
few years doingresearch @ Berkeleyin EECS dept!Slide9
OOP in BYOBSlide10
Express what computation desired without specifying how
it carries it outOften a series of assertions and queriesFeels like magic!Sub-categoriesLogicConstraintWe saw in Sketchpad!Example: PrologDeclarative Programmingen.wikipedia.org/wiki/Declarative_programming
Anders Hejlsberg“The Future of C#” @ PDC2008
channel9.msdn.com/pdc2008/TL16/Slide11
Five schoolgirls sat for an examination. Their parents – so they thought – showed an undue degree of interest in the result. They therefore agreed that, in writing home about the examination,
each girl should make one true statement and one untrue one. The following are the relevant passages from their letters:BettyKitty was 2ndI was 3rdEthelI was on topJoan was 2ndJoanI was 3rdEthel was lastKittyI came out 2ndMary was only 4thMaryI was 4th
Betty was 1st Declarative Programming ExampleSlide12
FunctionalEvaluate an expression and use the resulting value for something
Imperative First do this and next do thatObject-orientedSend messages between objects to simulate the temporal evolution of a set of real world phenomenaDeclarativeAnswer a question via search for a solutionWays to Remember the Paradigmswww.cs.aau.dk/~normark/prog3-03/html/notes/paradigms_themes-paradigm-overview-section.html
en.wikipedia.org/wiki/Programming_paradigmSlide13
Each paradigm has its unique benefitsIf a language is Turing complete, it is equally powerful
Paradigms vary in efficiency, scalability, overhead, fun, “how” vs “what” to specify, etc.Modern languages usually take the best from allE.g., ScratchCan be functionalCan be imperativeCan be object-orientedCan be declarativeSummary