COP 4020 Lecture -*- Outline -*- * Computation models and Programming Models (Preface) i.e., the preface of Peter van Roy and Seif Haridi's book, "Concepts, Techniques, and Models of Computer Programming" (MIT Press, 2004), where all references that are not otherwise attributed are found. ** Why study computation models and programming models? To study the thousands of programming langauges may have to - pick a small sample, or - step back from the details Q: How would we pick what to study? Look at programming techniques that are useful, study programming models and computational models ** What is a paradigm or programming model? See Robert W. Floyd, The Paradigms of Programming, CACM 22(8):455-460, August, 1979. ------------------------------------------ PROGRAMMING MODEL (OR PARAGIDM) def: a *programming model* (or *paradigm*) is ------------------------------------------ ... a way to design, code, test/verify/reason a way to approach problems in design a way to *organize* programs (a style) a set of questions how to evaluate a design/program what makes a good/bad design/program built on a set of tools (the computation model) variables, procedures, while-loops, declarations, ... Q: How is a paradigm different from a pattern? ** What is a computational model? (Preface) ------------------------------------------ COMPUTATION MODEL def: a *computation model* is ------------------------------------------ ... "a formal system that defines how computations are done." (p. xiii) It's a very small (core) programming language. *** parts It has: - data (with operations, means of computation), - structuring mechanisms (means of combination), and - abstraction mechanisms (means of abstraction) *** presentation Explained in terms of a "simple core language called its kernel language". (p. xiv) New concepts are added to the kernel incrementally. Practical language extensions (sugars and abstractions) are explained by rewriting them into the kernel. Combinations are used to demonstrate various blends of programming techniques. ** overview *** differences Q: How are programming and computation models different? programming model is connected to problem solving techniques programming model is larger, involves sugars and conveniences computation model is minimal Q: How are programming languages different from programming models? Important not to confuse a programming model with a particular language, there is poetry and prose both in Italian and English But sometimes intertwined (e.g., harder to rhyme in English) *** traditional view of programming paradigms ------------------------------------------ PROGRAMMING PARADIGMS !--------------------------------------! ! DECLARATIVE ! ! ! ! Logic Constraint ! ! ! ! CL ! ! ! !--------------------------------------! !--------------------------------------! ! ALGORITHMIC ! ! ! ! Imperative Higher-Order ! ! ! ! mostly- ! ! functional ! ! ! ! ! ! ! ! Object-based ! ! Applicative ! ! ! ! Object-oriented ! ! ! ! ! ! Aspect-oriented ! ! ! !--------------------------------------! ------------------------------------------ declarative = no statement of algorithm (differs from Hudak) logic = program is a logical theory + query horn clauses, unification constraint = program is list of constraints equations, constraint solving CL = constraint logic programming logical theory stated as constraints or constraints added to logic algorithmic = state algorithm imperative = program is sequence of changes to state (variables) assignment, while loops, etc. higher-order = program is building tools and applying them, or rule-based (somewhat equational) lambda abstraction procedures that takes procedures as args and return procedures as results (sometimes called functional) applicative = program is a set of rewrite rules, often build tools and then apply them no assignment (and no mutation), lambda abstraction Q: what problem motivates each style? Q: what languages are examples of each style? Examples: Declarative: OBJ3, SETL Logic: Prolog, \Prolog Constraint: Lotus 1-2-3 Constraint-Logic: CLP(R), Prolog III Algorithmic: CSP, GHC Imperative: FORTRAN, COBOL, BASIC, Algol 60, Algol 68, Pascal, C, PL/1 Object-based: Ada 83, CLU, Modula-2, Argus, SR, VisualBasic Object-oriented: Simula, Smalltalk, C++, Ada 95, Eiffel, Objective-C, Sather, ABCL/1, Emerald CLOS, Self, Cecil, Java, VB7 Aspect-oriented: AspectJ, HyperJ Higher-order: Applicative: SISAL, Miranda, Haskell Data-flow: Id Mostly-functional: Scheme, SML, CML, Lisp, Multilisp, APL Q: Where do languages like Python and Perl fit in? Q: How does concurrency fit in? Think about how to redraw this at the end of the semester. *** relationships between computation models (Appendix D) ------------------------------------------ GENERAL COMPUTATION MODEL (APPENDIX D) ______________________________________ |____________________________________| ||__________________________________|| ||| _______________________________||| ||||______________________________|||| |||||Declarative ||||| ||||| sequence, local, ||||| ||||| variable creation/binding||||| ||||| value creation ||||| ||||| procedures, if, case ||||| |||||____________________________||||| |||| |||| |||| Declarative concurrent |||| |||| thread |||| |||| by-need synchronization |||| ||||______________________________|||| ||| ||| ||| Security ||| ||| name creation, ||| ||| read-only views ||| |||________________________________||| || || || Exceptions || || try/catch, raise, || || failed values || ||__________________________________|| | | | Explicit state | | cell creation, cell exchange,| | boundness test | |____________________________________| ------------------------------------------ This is the model of the language Oz. Others that we will study are based on it. ** book's goals (skip if already covered) Understanding the fundamental concepts of programming models and computation models is the goal. Secondary goal, ability to design programming abstractions (p. xvii-xviii) (These relate to our Concepts and UseModels outcomes most directly.)