10.1 10. Language Paradigms Programming languages. Language paradigms. World view of imperative languages. World view of functional languages. World view.

Slides:



Advertisements
Similar presentations
Agenda Definitions Evolution of Programming Languages and Personal Computers The C Language.
Advertisements

Computational Models The exam. Models of computation. –The Turing machine. –The Von Neumann machine. –The calculus. –The predicate calculus. Turing.
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Programming Languages Language Design Issues Why study programming languages Language development Software architectures Design goals Attributes of a good.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Overview of Programming Paradigms
The Evolution of Programming Languages
COMP205 Comparative Programming Languages
Programming Languages Structure
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 1: Getting Started by George Lamperti & BU Faculty.
Introduction and Syntax. Course objectives Discuss features of programming languages. Discuss how the features are implemented in a simple computer architecture.
Summer 02-03Programming Language Concepts1 Programming Language Concepts (CS 360) Lecture 1: Overview, Grammars, and Little Languages Jeremy R. Johnson.
Programming Paradigms Imperative programming Functional programming Logic programming Event-driven programming Object-oriented programming A programming.
CS 331, Principles of Programming Languages Introduction.
314450: PROGRAMMING PARADIGMS Teaching scheme: Examination Scheme: Lectures: 3 Hours/Week Theory: 100 Marks OBJECTIVE: To understand the basic building.
Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.
Programming Languages CPS120: Introduction to Computer Science Lecture 5.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
Computer Architecture Computational Models Ola Flygt V ä xj ö University
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
Chapter 1 - Introduction
1 Programming Language History and Evolution In Text: Chapter 2.
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
Introduction To PROLOG World view of imperative languages. World view of relational languages. A PROLOG program. Running a PROLOG program. A PROLOG.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Programming Language 1. Programming language A programming language is a machine-readable artificial language designed to express computations that can.
© Kenneth C. Louden, Chapter 11 - Functional Programming, Part III: Theory Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
TIVDM2Functional Programming Language Concepts 1 Concepts from Functional Programming Languages Peter Gorm Larsen.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Logical and Functional Programming
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
int k = Integer.MAX_VALUE; k++; int k = Integer.MAX_VALUE; k++; What happens when the following code executes? byte b = someFile.readByte(); b = (byte)(b.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
Copyright © 2009 Elsevier Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Review for Test 2 Chapters 5 (start at 5.4), 6.1, , 12, 13, 15.1, Python.
a medium allowing humans and computers to communicate an abstraction of the real world a notation for expressing algorithms the set of all syntactically.
Language Paradigms CS655.
Functional Programming
Programming Language History and Evolution
Chapter 1. Introduction.
Programming Languages 2nd edition Tucker and Noonan
Concepts of Programming Languages
Why study programming languages?
PROGRAMMING LANGUAGES
Programming Language Design Concepts
课程名 编译原理 Compiling Techniques
Programming Language History and Evolution
Computer Programming.
Chap. 6 :: Control Flow Michael L. Scott.
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Ada – 1983 History’s largest design effort
Programming Languages
Chap. 6 :: Control Flow Michael L. Scott.
Programming Languages 2nd edition Tucker and Noonan
High Level Programming Languages
Principles of Programming Languages
Overview of Programming Paradigms
Lecture 8 Programming Paradigm & Languages. Programming Languages The process of telling the computer what to do Also known as coding.
Chapter 10: Compilers and Language Translation
Programming Languages, Preliminaries, History & Evolution
Presentation transcript:

Language Paradigms Programming languages. Language paradigms. World view of imperative languages. World view of functional languages. World view of relational languages. Imperative vs. Declarative world views. Referential transparency. Genealogy of programming languages.

10.2 Programming Languages What is a programming language? –A language for instructing a computer to solve a problem. Basic requirements for a programming language : –Universal : Turing machine equivalent. –Natural : Suited to solving the problems we want solved. –Implementable : Can be executed on a computer. –Efficient : Isn’t too slow or too memory hungry to be useful.

10.3 Basic Characteristics Of Programming Languages Syntax : –Grammar rules. –How to construct a valid program. Semantics : –Meaning rules. –What a valid program will do when run. Languages with similar syntax can have very different semantics (and vice versa). –C vs Java. –SQL vs. PROLOG. –SISAL vs. Haskell. Style of semantics defines paradigm of language.

10.4 Major Language Paradigms Paradigm  type. Each of the major paradigms is based on one of the mathematical models of computation. –Imperative : Von Neumann machine. –Functional : Lambda calculus. –Relational : Predicate calculus (Horn clauses). So far as I know there is no paradigm based on the most famous mathematical model of them all : the Turing machine. The Von Neumann model is the easiest one to build in hardware. –Von Neumann machine is essentially a single processor computer. Most programming languages are imperative. Declarative Paradigms Declarative Paradigms

10.5 Paradigms & Computational Models Each paradigm has its own computational model. –World view. –Its model of what computation actually is. To understand a paradigm you must understand its world view. Why do we want to understand different programming paradigms? “If all you have is a hammer, then every problem looks like a nail”. -- Baruch’s observation. No one paradigm has the best world view for all problems. One aim of this course is to help you decide which paradigm is best suited to the problem at hand.

10.6 World View Of Imperative Languages Processor executes instructions stored in memory. –Instructions modify memory contents, read input and / or write output. Contents of memory + input not yet read + output written so far = state. Memory Processor inputoutput bytes

10.7 World View Of Imperative Languages II Imperative world view is based on state. –Imperative program = sequence of instructions which modify state (i.e. statements). –Result of computation is state after the computation has terminated. Most computers are Von Neumann machines. –Have the same world view as imperative languages. –Little translation overhead. –Imperative languages run efficiently on them. Imperative languages tend to use Von Neumann hardware as efficiently as possible. Imperative languages tend to use programmer time as inefficiently as possible.

10.8 World View Of Functional Languages Usually written : output = program input The program is a function which is applied to the input to calculate the output. No notion of a state which can be modified so no statements. No memory in the model so no variables to assign to. Functional programs do have variables but they are mathematical variables (n.b. Backus’ FP). –Similar to constants in imperative languages. Cannot be changed, can only be redefined (i.e. redeclared). Have a constant value in a given scope. program inputoutput

10.9 World View Of Functional Languages II Example : functional (Haskell) program to compute a factorial. factorial n = foldl (*) 1 [1..n] Program defines what a factorial is. Does not explicitly tell a Von Neumann computer how to compute it by state modifications. Instructive to compare the above with the equivalent imperative code (e.g. for C). Functional program a lot shorter because there is no consideration of memory. Functional program a lot less efficient (on a Von Neumann machine) because there is no consideration of memory.

10.10 World View Of Relational Languages Usually written : program(input, output) The program is a relation which holds between the input and the output. No notion of a state which can be modified so no statements. No memory in the model so no variables to assign to. Relational programs do have variables but they are logical variables. –Logical variables take on the values required to make the relations containing them hold. program inputoutput

10.11 World View Of Relational Languages II Example : relational (PROLOG) program expressing some facts about things I like. likes(dave, functions). likes(dave, history). likes(dave, cricket). likes(dave, beer). likes(dave, fags). likes(dave, sci-fi). likes(dave, anoraks). likes(dave, X) :- likes(X, functions), likes(X, cricket), likes(X, sci_fi), likes(X, history). Program defines what some of the things I like are. Does not explicitly tell a Von Neumann computer how to decide whether I like something by state modifications.

10.12 World View Of Relational Languages III Instructive to compare the above with the equivalent imperative code (e.g. for C). Relational program a lot shorter because there is no consideration of memory, input and output. Relational program a lot less efficient (on a Von Neumann machine) because there is no consideration of memory, input and output. Relational program also shorter and much less efficient than the equivalent functional program. –Relational paradigm is a lot further from the Von Neumann model than functional one. One obvious abstraction from Von Neumann and Lambda calculus models: no real distinction between input and output. –There is no real notion of input or output.

10.13 World View Of Relational Languages IV Can run a relational program backwards : give the program the output and it returns the input. Running the program forwards we could type the query likes(dave, X) which would produce something like [functions, history, cricket, beer, fags, sci-fi, anoraks, dave ] Running the program backwards we could type the query likes(X, cricket) which would produce something like [ dave ] Relational programs are bi-directional.

10.14 Imperative vs. Declarative World Views Very simplistic view : –In an imperative program we must tell the computer exactly how to solve the problem. –In a declarative program we only need to tell the computer what the problem is. The computer works out how to solve the problem itself. Simplistic, and inaccurate. More sophisticated view : –In an imperative program variables are bound to store locations. –In a declarative program variables are bound to values. Major consequence : declarative programs exhibit referential transparency; imperative programs don’t. –Referential transparency is a good thing.

10.15 Referential Transparency Variables cannot be changed (although variables can be re- declared). –Value of a variable cannot change within a given scope. –Declarative language variable  imperative language constant. Programs are easier to understand / reason about / prove. Correctness preserving program transformation. f(x) + g(x)  g(x) + f(x) Can’t guarantee this in an imperative language. Allows fold / unfold transformation (a.k.a.  -transformation). –A variable can always be replaced by its definition. –Prolog is not truly declarative (  -transformation doesn’t always work).

10.16 Pure & Impure Languages A pure language is one which exhibits the characteristics of only one major paradigm. Purely imperative languages include COBOL, FORTRAN, C, PL/1, Pascal and Algol. Purely functional languages include Haskell, Miranda, Gofer, Hugs, Hope and KRC. There are no purely relational languages (so far as I know). This is largely because the concept of I/O cannot really exist within the relational model. Impure languages exhibit the characteristics of two or more major paradigms. –PROLOG is imperative and relational. –LISP and ML are imperative and functional. –POPLOG is imperative, functional and relational.

10.17 Minor Language Paradigms The minor paradigms are extensions to / adaptations of the major paradigms. Concurrent : imperative, functional and relational. –Computation (and state) is partitioned between processes. –Multiple execution images of a particular process can be created. Object oriented : imperative only although functional and relational OO languages are claimed to exist. –Computation and state is partitioned between classes. –Classes may inherit attributes from other classes. –Classes may re-define the behaviour of operations upon them (overloading). –Multiple instances (i.e. objects) of a particular class can be created.

10.18 Minor Language Paradigms II Dataflow : usually functional although the most famous example (LUCID) has an imperative style syntax. –Data flows through parallel nodes which apply functions to it to produce results. 4GLs : essentially imperative (occasionally relational). –Basically, programming environments for specialist applications. –Usually produce imperative language programs as output (often COBOL or these days, C). Interface programming : essentially imperative. –Reactive programming : computation is partitioned between buttons and dialog boxes.

10.19 Minor Language Paradigms III Real-time : usually imperative although some lunatics have created functional (e.g. Ruth) and relational (e.g. Partlog) real-time languages. –Time expressibility is required : language constructs to talk about when things happen as well as what things happen. Many other minor paradigms could be identified. –Largely a matter of taste whether a group of languages with similar characteristics is classified as a minor paradigm. Note that many languages can be categorised as being in more than one minor paradigm. –Lustre is a real-time, dataflow language. –Ada is a concurrent, object-oriented, real-time language.

10.20 Purity & The Minor Paradigms Most minor paradigm languages satisfy the definition of purity : they only exhibit characteristics from one major paradigm (usually the imperative paradigm). Concurrent languages include Ada, occam, Modula-2, Modula-3, PARLOG, Concurrent PROLOG, PFL and CAML. Object oriented languages include Ada, C++, Java, Smalltalk, Eiffel and Simula. Dataflow languages include LUCID, Lustre, Signal and Esterel. 4GL languages include Visual Basic and Javascript. Interface languages include HTML, TK/TCL, Visual Basic, Java. Real-time languages include Lustre, Ada, VxWorks C, Coral-66.

10.21 Health Warning The classifications into major and minor paradigms and into pure and impure languages are personal ones. –Could argue that the minor paradigms are as fundamental as the major ones. –Could have some other definition of purity. Could be argued that structured programming deserves inclusion as a minor paradigm. Could be argued that heuristic methods deserve inclusion as a major paradigm. For the purposes of this course my classifications have two major strong points : –They are based on mathematical principles and so are easy to defend. –I mark the exam papers.

10.22 Genealogy Of Programming Languages LISP PROLOG ML Miranda Haskell/Gofer FORTRAN COBOLALGOL 60 ALGOL 68 PL/1 C Pascal Simula Smalltalk Ada C++ Eiffel Java

10.23 Summary Programming language must be universal, natural, implementable and efficient. Style of semantics of language defines paradigm. Major paradigms : –Imperative : Von Neumann machine. –Functional : Lambda calculus. –Relational : Horn clause predicate calculus. Imperative : variables bound to store locations. –Efficiency (on Von Neumann machines). Declarative (i.e. functional or relational) : variables bound to values. –Referential transparency.

10.24 Summary II Minor paradigms : –Concurrent. –Object oriented. –Dataflow. –4GLs. –Interface programming. –Real-time. Could identify many others. –Most minor paradigm languages fit in more than one minor paradigm.