1 / 38

Programming Languages

Programming Languages. Evaluation of Programming Languages and Computational Paradigms. Asst. Prof. Dr. Ahmet Sayar Spring-2013 Kocaeli University Computer Engineering Department. Programming Domains. Scientific applications Large number of floating point computations

lapis
Télécharger la présentation

Programming Languages

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 Languages Evaluation of Programming Languagesand Computational Paradigms Asst. Prof. Dr. AhmetSayar Spring-2013 Kocaeli University Computer Engineering Department

  2. Programming Domains • Scientific applications • Large number of floating point computations • FORTRAN and ALGOL 60 • Business applications • Produce reports, use decimal numbers and characters • COBOL • Artificial intelligence • Symbols rather than numbers manipulated • LISP (1965) • Logic programming using PROLOG (1997)

  3. Programming Domains • Systems programming • Need efficiency because of continuous use • IBM PL/S (a dialect of PL/I – 1970s) • UNIX (1989 in C) • Scripting languages (VHLL-Very high level languages) • Put a list of commands in a file to be executed • The first language named sh (shell) • Ksh (developed at Bell lab -1995) • Tcl (developed at Berkeley -1994) • Perl (2000) – combination of shell and awk • Popularity increased by www - good for CGI programming • JavaScript (developed by Netscape) • Special-purpose languages

  4. Language Evaluation Criteria • Readability • Writability • Reliability • Cost

  5. The ease with which programs Control statement Earlier version of FORTRAN does not have a loop control, instead the goto statement are used to implement loops In FORTRAN 77 style: L1: if (inc > 20) go to Out; L2: if (sum > 100) go to Next; sum+ = inc; go to L2; Next: inc++; go to L1; Out: Readability • In C: • while (inc  20) { • while (sum  100) { • sum+= inc; • } • inc++; • }

  6. firstName[3]; lastName[3]; id[3]; Salary[3]; Employee[3]; Readability (cont.) • Data Types and Structures • Inadequate data types and structures reduce readability • In a language without Boolean type, an integer values may be used to indicate true or false • classFull = 1 vs. classFull = true • In a language without Record type, multiple arrays may have to be used for multiple attributes string firstName[100]; string lastName[100]; int id[100]; float salary[100]; typedefstruct { string firstName; string lastName; int id; float salary; } EmployeeType; EmployeeType employee[100];

  7. Readability (cont.) • Overall simplicity • A language that has a large number of basic components is more difficult to learn than one with a small number of basic components • Orthogonality • Relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language.

  8. Writability • Writability is a measure of how easily a language can be used to create programs for a chosen problem domain • Factors: • Simplicity and orthogonality • Support for abstraction • Process and data abstractions • Ability to define and then use complicated structures or operations in ways that allow many of the details to be ignored • Expressivity • Count++ or count=count+1 ?

  9. Reliability • Type checking • Testing for type errors in a given program, either by the compiler or during program execution • Exception handling • c? c++? Java? • Aliasing • Readability and writability

  10. Cost • Categories • Training programmers to use language • Writing programs • Compiling programs • Executing programs • Language implementation system • Reliability • Maintaining programs • Others: portability, generality (wide range of application), well-definedness

  11. Language Design Trade-Offs • Reliability vs. cost of execution • Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs • Writability (flexibility) vs. reliability • Example: C++ pointers are powerful and very flexible but are unreliable

  12. Computational Paradigms

  13. Influences on Language Design • Computer architecture: Von Neumann • We use imperative languages, at least in part, because we use von Neumann machines • Data and programs stored in same memory • Memory is separate from CPU • Instructions and data are piped from memory to CPU • Basis for imperative languages • Variables model memory cells • Assignment statements model piping • Iteration is efficient

  14. Von Neumann Architecture

  15. Imperative Languages • A programming language that is characterized by the following characteristics is called imperative language (von Neumann model) • The sequential execution, the use of variables • Representing memory locations • The use of assignment to change the values of variables • Such languages are also called procedural

  16. Von Neumann Bottleneck • The requirement that computation be described as a sequence of instructions, each operating on a single piece of data, is sometimes referred to as the von Neumann bottleneck • It restricts the ability of a language to indicate parallel computation • Is there any way to describe computation that are less dependent on von Neumann model of a computer???

  17. Influence on Language Design • Programming Methodologies • Procedure-oriented programming (late 60s - early 70s) • Cost shift : from hardware to software development • Programs are executed through successive procedure calls • Data-oriented programming (late 70s) • Focuses on using abstract data types to solve problems • The first language supporting Simula 67 • Object-oriented programming (early 80s) • Data abstraction, inheritance and dynamic binding • The first language supporting SmallTalk

  18. Programming Paradigms • Imperative • Structured Programming • Object Oriented Programming • Distributed Programming • Declarative • Functional Programming • Logic Programming • Database Languages

  19. 1. Imperative Languages • Describes computation in terms of statements that change a program state • Central features are variables, assignment statements, and iteration • Imperative programs define sequences of commands for the computer to perform • Control is the responsibility of the programmer • It is much more in tune with the computer community's way of thinking • Data is placed in a data structure and the data structure is manipulated by various procedures. • C, Fortran, Pascal, Pascal

  20. 2. Declarative Languages • Expresses what the program should accomplish without prescribing how to do it in terms of sequences of actions to be taken • Expresses the logic of a computation without describing its control flow • No assignment for the variables • Lisp, Scheme, SQL

  21. 1.1. Structured Programming • Structured programs are often composed of simple, hierarchical program flow structures. These are sequence, selection, and repetition. • It has a syntax for enclosing structures between bracketed keywords, such as an if-statement bracketed • It is most famous for removing or reducing reliance on the GOTO statement. • Well known examples: C, Fortran, PL/I, Pascal, Cobol, Ada.

  22. 1.2. Object Oriented Programming • An abstraction and generalization of imperative programming. • Involves collections of objects each with a state and a set of operations to transform the state. • Focuses on data rather than on control. • As in the real world, objects interact so object-oriented programming uses the metaphor of message passing to capture the interaction of objects. • Encapsulate data objects with processing • Inheritance and dynamic type binding • Grew out of imperative languages • C++, Java

  23. Object Oriented Programming

  24. 1.3. Distributed Programming • Distributed computing is a field of computer science that studies distributed systems. • A distributed system consists of multiple autonomous computers that communicate through a computer network • A computer program that runs in a distributed system is called a distributed program, and distributed programming is the process of writing such programs • There are several autonomous computational entities, each of which has its own local memory. • The entities communicate with each other by message passing. • The computational entities are called computers or nodes. • WHY Distributed systems ?

  25. Distributed Programming Loosely coupled vs. Tightly Coupled

  26. 2.1. Functional Programming 1 • Functional programming is a style of programming in which the basic method of computation is the application of functions to arguments. • Functional programming involves creating and manipulating functions to build up larger programs. • The abstract nature of functional programming leads to considerably simpler programs. • Ex: summing the integers from 1 to 10 • Sum[1..10] in Haskell • The computation method is function application • Examples: Lisp, Scheme, ML, Miranda and Haskell

  27. Functional Programming - 2 • Involves no notion of variable or assignment to variables • Concentrates on values and functions instead of memory locations • Repetitive operations are not expressed by loops but by recursive functions

  28. Functional Programming - 3– Ex: Scheme • In a functional programming language, certain functions, called primitive functions, are defined as part of the language. Other functions can be defined and named by the programmer. To define the doubling function using Scheme you could say (define (double x) ( * 2 x) • Scheme responds immediately to a function invocation by displaying the result so the following will occur using the numbers 5 and 7. (double 5) 10

  29. Functional Programming – 4Lambda Calculus • Functional programming has its roots in lambda calculus, • A formal system developed in the 1930s to investigate function definition, function application, and recursion. • Many functionalprogramming languages can be viewed as elaborations on the lambda calculus.

  30. Functional Programming - 5 • Common functional programming language and its gcd application is given below In scheme dialect of LISP:

  31. History of Functional Programming • 1930: Alonzo Church develops the lambda calculus, a simple but powerful theory of functions • 1950s: John McCarthy develops Lisp, the first functional language, with some influences from the lambda calculus, but retaining variable assignments • 1970s: John Backus develops FP, a functional language that emphasizes higher-order functions and reasoning • 1970s : Robin Milner and others develop ML, the first modern functional language, which introduced type inference and polymorphic types • 1970s-1980s: David Turner develops Miranda system • 1987: An international committee of researchers initiates the development of Haskell, a standard lazy functional language

  32. 2.2. Logic Programming - 1 • A set of axioms, or rules, defining relationships between objects • The art of logic programming is constructing concise and elegant programs that have the desired meaning • There are three basic statements: facts, rules and queries. There is a single data structure: the logical term • Logic programming is, basically, the use of mathematical logic for computer programming. • Rule-based • No special order in rules • Prolog

  33. Logic Programming - 2 • A program consists of a set of statements that describe what is true about a desired result, as opposed to giving a particular sequence of statements that must be executed in a fixed order to produce the result • Prolog is widely used logic programming • Example code for gcd

  34. Logic Programming - 3

  35. Logic Language: PROLOG - 4 • The best-known logic programming language is Prolog. • Prolog programs consists of facts and rules. A fact expresses a property about a single object or a relationship among several objects. • Example: A Prolog program written for American history. president (lincoln , gettysburg_address). president (lincoln, civil_war). president (nixon. first_moon_landing). president (jefferson, lewis_and_clark). president (kennedy, cuban_missle_crisis). president (fdr, world_war_II). before (jefferson, lincoln). before (lincoln, fdr). before (fdr, kennedy). before (kennedy, nixon). Facts about: U.S. presidents were in office when certain events occurred Facts about: Chronology order of those presidents terms in office

  36. Exercises • ?-before(lincoln, fdr) • ?-president (jefferson, lewis_and_clark) • ?-before(first_moon_landing , cuban_missle_crisis)

  37. 2.3. Database Programming • SQL • Definition Language DDL • Manipulation Language DML • Can be embedded in other languages

  38. Questions? • In what language UNIX is written? • What is aliasing? • What is exception handling? • What does it mean for a program to be reliable? • What arguments can you make for the idea of a single language for all the programming domains? • Describe the advantages and disadvantages of some programming environments you have used.

More Related