1 / 20

Programming Languages 2nd edition Tucker and Noonan

Programming Languages 2nd edition Tucker and Noonan. Chapter 1 Overview A good programming language is a conceptual universe for thinking about programming. A. Perlis. Paradigms of Programming Languages.

kyros
Download Presentation

Programming Languages 2nd edition Tucker and Noonan

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Programming Languages2nd editionTucker and Noonan Chapter 1 Overview A good programming language is a conceptual universe for thinking about programming. A. Perlis

  2. Paradigms of Programming Languages 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)

  3. 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, …

  4. The von Neumann-Eckert Model

  5. Object-oriented (OO) Paradigm An 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

  6. Functional Paradigm Functional 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, …

  7. Functional vs Imperative • Compute Factorial Function • In Imperative Programming Languages: • In Functional Programming Languages: Scheme 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))) ))

  8. Logic Paradigm Logic 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

  9. Logic vs Imperative • Concatenate two strings: • In Imperative Programming Languages: • In Logic Programming Languages: Prolog append([], X , X). The empty list concatenated with any other list, say X, returns that other list, X, as the result append(Tail, Y, Z) append([Head|Tail], Y, [Head|Z]) :- If Z is the result of concatenating lists Tail and Y, then Concatenating any new list [Head|Tail] with Y gives the result [Head | Z]

  10. Example append([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])

  11. A Brief History of Programming Languages

  12. What makes a successful language? Key characteristics: • Simplicity and readability • Clarity about binding • Reliability • Support • Abstraction • Orthogonality • Efficient implementation

  13. 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

  14. 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

  15. Language Support • Accessible (public domain) compilers/interpreters • Good texts and tutorials • Wide community of users • Integrated with development environments (IDEs)

  16. Abstraction in Programming • Data • Programmer-defined types/classes • Class libraries • Procedural • Programmer-defined functions • Standard function libraries

  17. 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

  18. Compilers and Virtual Machines 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)

  19. The Compiling Process

  20. The Interpreting Process

More Related