Programming Languages and Paradigms

Slides:



Advertisements
Similar presentations
1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Advertisements

Programming Languages and Paradigms
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
High-Level Programming Languages
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
The Evolution of Programming Languages
Programming Languages Structure
Introduction and Syntax. Course objectives Discuss features of programming languages. Discuss how the features are implemented in a simple computer architecture.
Presented by Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion.
1 Programming Languages Marjan Sirjani 2 1- The Study of Programming Languages The purpose of language is simply that it must convey meaning. (Confucius)
CS 415: Programming Languages Chapter 1 Aaron Bloomfield Fall 2005.
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.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
Chapter 1 - Introduction
By Neng-Fa Zhou1 Evolution of programming languages –Machine language –Assembly language –Sub-routines and loop (Fortran) –Procedures and recursion (Algol,
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © 2007 Addison-Wesley. All rights reserved.1-1 Reasons for Studying Concepts of Programming Languages Increased ability to express ideas Improved.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Logical and Functional Programming
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
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.
LECTURE 1 Overview and History. COURSE OBJECTIVE As I stated before, our ultimate objective in this course is to provide you with the knowledge and skills.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 190 Programming Language Paradigms Fall 2014
Functional Programming. Some Functional Languages Lisp Scheme - a dialect of Lisp Haskell Miranda.
Ada, Scheme, R Emory Wingard. Ada History Department of Defense in search of high level language around Requirements drafted for the language.
A Short History of PL's (MacLennan 1999) “Zeroth Generation” (1940's-50's): machine language / assembly: if/then, read/write, store, goto
Programming Language Theory 2014, 1 Chapter 1 :: Introduction Origin : Michael L. Scott School of Computer & Information Engineering,
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.
Programming Language History and Evolution
Chapter 1. Introduction.
Programming Languages 2nd edition Tucker and Noonan
Functional Programming
CSCE 190 Programming Language Paradigms
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
Concepts of Programming Languages
Why study programming languages?
CSCI 3200: Programming Languages
CS 326 Programming Languages, Concepts and Implementation
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
Computer Programming.
CS 363 – Chapter 1 What is a programming language? Kinds of languages
课程名 编译原理 Compiling Techniques
Programming Language History and Evolution
Evolution of programming languages
Chap. 6 :: Control Flow Michael L. Scott.
Welcome to Programming Languages!
FP Foundations, Scheme In Text: Chapter 14.
Chap. 6 :: Control Flow Michael L. Scott.
Programming Languages 2nd edition Tucker and Noonan
CS 36 – Chapter 11 Functional programming Features Practice
High Level Programming Languages
Low Level Programming Languages
Von Neumann Architecture
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.
강의 내용 및 방법 접근방법 리포트 시험 Lambda Calculus, Proof of Correctness
School of Computer & Information Engineering,
Programming Languages, Preliminaries, History & Evolution
CSCI 3200: Programming Languages
Presentation transcript:

Programming Languages and Paradigms History on programming Why are there so many languages What makes a language successful Spectrum of programming languages

Brief History on Computer Programming Programming with the first electronic computers in 1940s Filling several rooms, costing millions of 1940s dollars Computer’s time was more valuable than programmer’s They programmed in machine languages (sequence of bits) 27bdffd0 afbf0014 0c1002a8 00000000 0c1002a8 afa2001c ... Requiring a less error-prone notation, inventing assembly language addiu sp, sp, -32 sw ra, 20(sp) jal getint nop sw v0, 28(sp)

Brief History on Computer Programming Translating from assembly language into machine language is straightforward due to one-to-one correspondence: assembler But people began to wish for a machine-independent language Frustrating to rewrite assembly program for every new machine Difficult to maintain large assembly programs Especially for numerical programs Fortran was developed in mid-50s, followed by Lisp and Algol Translating from high-level language into assembly language is more complicated than assemblers: compiler Fortran program was slower at first than assembly program But over time, performance gap narrowed, and eventually reversed (pipelining, ILP); optimizing compiler usually generates better code Also, it is now important to economize programmer’s efforts in development and maintenance (time-to-market is more important)

Why Are There So Many Programming Languages? Evolution: constantly finding better ways to do programming e.g. structured programming: in 60s and early 70s, goto-based Fortran, Cobol, Basic gave way to while loops case statements e.g. object-oriented programming: in late 80s, nested block-structured Pascal, Algol, Ada gave way to OO-structured C++, Smalltalk, Eiffel Special purpose: many designed for specific domain Lisp for manipulating symbolic data and complex data structures C is good for low-level system programming (notably, for UNIX) Prolog is good for reasoning about logical relationship among data Snobol is good for manipulating character strings Personal preference: different people like different things Some people like the terseness of C or C++; some hate it Some people like to think recursively; others prefer iteration Some people like to work with pointers; others like implicit dereference

What Makes a Language Successful? Expressive power: more “powerful” than others In principle, all languages are equivalent (Church’s conjecture) Still, language features have a huge impact in writing good code Ease of use for novice: “learning curve” is important Basic was successful due to its very low learning curve Part of reasons for Java’s success Ease of implementation: Basic: implemented on tiny machines Pascal: simple, portable implementation with free distribution (Pascal compiler, P-code, P-code interpreter) Java: similar simple implementation

What Makes a Language Successful? Excellent compilers Fortran compilers have been extremely good (also its language design) Common Lisp was successfully partly because its compiler and tools Economics, patronage and inertia: non-technical factors Powerful sponsor: Cobol and PL/1 to IBM, Ada to DoD Huge base of installed software Need to consider viewpoints of both programmers and implementors In early days, implementor’s viewpoint was important; PL is a means of telling a computer what to do (implementation efficiency) But for programmers, PL is a means of expressing algorithms, constraining what can/cannot be expressed; so it affects what programmer can think (conceptual clarity) Knuth says “programming is art of telling another human what on wants computer to do” (compromise of both efficiency and clarity)

Programming Language Spectrum PLs can be classified based on their computation models Declarative Focus is what the computer is to do (programmer’s viewpoint) subclassified into: Functional: Lisp.Scheme, ML, Haskell Logic : Prolog, VisiCalc Dataflow : Id, Val Imperative Focus is how the computer should do it (implementor’s viewpoint) Imperative predominates mainly for performance reasons subclassified into von Neumann : Fortran, Pascal, C, Basic, ... Object-oriented: C++, Java, Smalltalk, Eiffel

Functional Language Computational model based on recursive definition of functions Inspired by lambda calculus, a formal model by Church in 30’s Program is considered a function from input to output Lisp, Scheme, ML, Haskell Most scheme/Lisp interpreter repeats: read-evaluate-print (+ 3 4) 7 To create a function, one evaluates a lambda expression: (lambda (x) (* x x)) => function Calling a function ((lambda (x) (* x x)) 3) => 9

Scheme/Lisp Computational model based on recursive definition of functions (car ‘(2,3,4)) => 2 (cdr ‘(2,3,4)) => (3,4) (cons 2 ‘(3,4)) => (2,3,4) High-order functions (functions that take functions as arguments) (define compose (lambda (f g) (lambda (x) (f (g x))))) (compose car cdr) ‘(1,2,3)) => 2

Logic or Constraint-Based Language Computational model inspired by propositional logic (e.g. Prolog) Programmer states a collection of axioms; user states a theorem (goal), and the system find axioms that satisfy the goal Axioms are specified in Horn clauses H <- B1, B2, B3, .., Bn (meaning that H is true is B1, B2,..Bn are true) New statements are derived through resolution C <- A, B D <- C ---------- D <- A,B During resolution, free variables may get values via unification wet (X) <- rainy (X) rainy (Seoul) (Horn clause for a fact) ---------------- wet (Seoul)

Prolog There are three types of Horn clauses List processing Fact (w/o RHS) rainy(Seattle). rainy(Seoul). cold(Seoul) Rule snowy(X) <- rainy(X), cold(X) Query (goal) ?- snowy(C) C = Seoul List processing append( [], A, A). Append( [H | T], A, [H|L]) :- append(T, A, L) ?- append([a,b,c], [d,e], L) L = [a,b,c,d,e]

Dataflow Language Computation model based on data flows rather than control flows Flow of information (tokens) among primitive functional nodes Provides inherently parallel model of computation: nodes are triggered by arrivial of input tokens Id, Val, Sisal

Von Neumann Language Computational model based on modification of variables Computing via side-effects While function PL are based on expressions that have values, von Neumann PL are based on statements (assignments) that influence subsequent computation by changing the value of memory Fortran, C, Pascal, Basic, ...

An Example: GCD (a,b) Imperative programmers says: To compute GCD of a and b, check if a and b are equal. If so, print one of them and stop. Otherwise, replace the larger one by their difference and repeat program gcd (input, output) var I, j: integer; begin read (I, j); while I <> j do if I > j then I = I - j else j = j - I; writeln (I); end

An Example: GCD (a,b) Functional programmers says: The GCD of a and b is defined to be a when a and b are equal, and to be the GCD of c and d when a and b are unequal, where c is the smaller of a and b, and d is their difference. To compute the gcd of a given pair of numbers, expand and simplify this until finish Logic programmer says The proposition gcd (a,b,g) is true if (1) a, b, g are all equal, or (2) there exists numbers c and d such that c is the minimum of a and b (I.e., min(a,b,c) is true), d is their difference (I.e., minus (a,b,d) is true), and gcd(c,d,g) is true. To compute the gcd of a given pair of numbers, search for a number g for which these two rules allow one to prove that gcd (a,b,g) is true

Object-Oriented Language Related to von Neumann but has a more structured and distributed model of both memory and computation Rather than picture computation as a monolithic processor on a monolithic memory, OO picture it as interactions among semi-independent objects, each of which has its own state and executable functiosn to manage that state C++, Java, Smalltalk, .. We will now talk about the paradigm of object-oriented programming in detial