copyright © 2006 the mcgraw-hill companies, inc. programming languages 2nd edition tucker and...
DESCRIPTION
Copyright © 2006 The McGraw-Hill Companies, Inc. Imperative Paradigm Follows the classic von Neumann-Eckert model: –Program and data are indistinguishable in memory –Program = a sequence of commands –State = values of all variables when program runs –Large programs use procedural abstraction Example imperative languages: –Cobol, Fortran, C, Ada, Perl, …TRANSCRIPT
![Page 1: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/1.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Programming Languages2nd edition
Tucker and Noonan
Chapter 1Overview
A good programming language is a conceptual universe for thinking about programming.
A. Perlis
![Page 2: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/2.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
A programming paradigm is a pattern of problem-solving thought that underlies a particular genre of programs and languages.
There are four main programming paradigms:– Imperative– Object-oriented– Functional– Logic (declarative)
Paradigms of Programming Languages
![Page 3: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/3.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Imperative Paradigm
Follows the classic von Neumann-Eckert model:– Program and data are indistinguishable in memory– Program = a sequence of commands– State = values of all variables when program runs– Large programs use procedural abstraction
Example imperative languages: – Cobol, Fortran, C, Ada, Perl, …
![Page 4: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/4.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
The von Neumann-Eckert Model
![Page 5: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/5.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Object-oriented (OO) ParadigmAn OO Program is a collection of objects that interact by passing messages
that transform the state.
When studying OO, we learn about:– Sending Messages– Inheritance– Polymorphism
Example OO languages:
Smalltalk, Java, C++, C#, and Python
![Page 6: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/6.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Functional ParadigmFunctional programming models a computation as a
collection of mathematical functions.– Input = domain– Output = range
Functional languages are characterized by:– Functional composition– Recursion
Example functional languages:– Lisp, Scheme, ML, Haskell, …
![Page 7: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/7.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
• Compute Factorial Function– In Imperative Programming Languages:
– In Functional Programming Languages: Scheme
Functional vs Imperative
fact(int n) { if (n <= 1) return 1; else return n * fact(n-1); }
(define (fact n) (if (< n 1) 1 (* n (fact (- n 1)))))
![Page 8: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/8.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Logic ParadigmLogic programming declares what outcome the program
should accomplish, rather than how it should be accomplished.
When studying logic programming we see:– Programs as sets of constraints on a problem– Programs that achieve all possible solutions– Programs that are nondeterministic
Example logic programming languages: – Prolog
![Page 9: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/9.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Logic vs Imperative• Concatenate two strings:
– In Imperative Programming Languages:– In Logic Programming Languages: Prolog
append([], X , X).
append(Tail, Y, Z)append([Head|Tail], Y, [Head|Z]) :-
The empty list concatenated with any other list, say X, returns that other list, X, as the result
If Z is the result of concatenating lists Tail and Y, then Concatenating any new list [Head|Tail] with Y gives theresult [Head | Z]
![Page 10: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/10.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Exampleappend([english, russian], [spanish], L)
H= english, Tail = [russian], Y=[spanish], L=[english|Z]
append([russian],[spanish],[Z])
H=russian, Tail=[], Y=[spanish], [Z]=[russian|Z’]
append([],[spanish],[Z’]).
X =[spanish], Z’ = [spanish]
append([], [spanish], [spanish])
![Page 11: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/11.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
A Brief History of Programming Languages
![Page 12: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/12.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
What makes a successful language?Key characteristics:
– Simplicity and readability– Clarity about binding– Reliability– Support– Abstraction– Orthogonality– Efficient implementation
![Page 13: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/13.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Simplicity and Readability• Small instruction set
– Is a smaller number of instructions better?
• Simple syntax– More than one way to accomplish a particular op,– A single op has more than one meaning
• Benefits:– Ease of learning– Ease of programming
![Page 14: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/14.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Reliability
A language is reliable if:– Program behavior is the same on different platforms
• E.g., early versions of Fortran
– Type errors are detected• E.g., C vs Haskell
– Semantic errors are properly trapped• E.g., C vs C++
– Memory leaks are prevented• E.g., C vs Java
![Page 15: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/15.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Language Support
• Accessible (public domain) compilers/interpreters• Good texts and tutorials• Wide community of users• Integrated with development environments (IDEs)
![Page 16: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/16.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Abstraction in Programming
• Data– Programmer-defined types/classes– Class libraries
• Procedural– Programmer-defined functions– Standard function libraries
![Page 17: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/17.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Orthogonality
A language is orthogonal if its features are built upon a small, mutually independent set of primitive operations.
• Fewer exceptional rules = conceptual simplicity– E.g., restricting types of arguments to a function
• Tradeoffs with efficiency
![Page 18: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/18.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
Compiler – produces machine code
Interpreter – executes instructions on a virtual machine
• Example compiled languages:– Fortran, Cobol, C, C++
• Example interpreted languages:– Scheme, Haskell, Python
• Hybrid compilation/interpretation– The Java Virtual Machine (JVM)
Compilers and Virtual Machines
![Page 19: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/19.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
The Compiling Process
![Page 20: Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is](https://reader035.vdocument.in/reader035/viewer/2022081805/5a4d1acc7f8b9ab05996ff30/html5/thumbnails/20.jpg)
Copyright © 2006 The McGraw-Hill Companies, Inc.
The Interpreting Process