Vous êtes sur la page 1sur 29

Principles of Programming Languages

Evaluation of Programming Languages


Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department

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), SCHEME (a dialect of LISP)

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
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 sh and awk
Popularity increased by www - good for CGI programming

JavaScript (developed by Netscape)

Special-purpose languages

Readability
Control statement
Earlier version of FORTRAN does not have a loop control, instead the goto statement are used to implement loops In C: while (inc 20) { while (sum 100) { sum+= inc; } inc++; } 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:

Language Evaluation Criteria


Writability
Factors:
Simplicity and orthogonality Support for abstraction
Process and data abstractions

Expressivity
Count++ or count=count+1 ?

Reliability
Factors:
Type checking Exception handling
c? c++? Java?

Aliasing Readability and writability

Language Evaluation Criteria


Cost
Categories
Training programmers to use language Writing programs Compiling programs Executing programs Language implementation system Reliability Maintaining programs

Others: portability, generality, welldefinedness

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

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

Von Neumann Architecture

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

Programming Paradigms
1. Imperative
Structured Programming Object Oriented Programming Distributed Programming

2. Declarative
Functional Programming Logic Programming Database Languages

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 C, Fortran, Pascal, Pascal

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

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.

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

Object Oriented Programming

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 ?

Distributed Programming

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

Functional Programming Ex: Scheme 2


In a functional programming language, certain functions, called primitive functions or just primitive, 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 (double 7) 14 What is the difference between a mathematical function and the notion of a function used in imperative programming language?

Functional Programming - 3
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

Functional Programming - 4
Common functional programming language and its gcd application is given below

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

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

Logic Programming - 3

1-25

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. As an example, a Prolog program was written for American history. The example consisted of which U.S. presidents were in office when certain events occurred and in the chronology order of those presidents terms in office. Here are the short list of facts (declarations): 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).

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

2.3. Database Programming


SQL Definition Language DDL Manipulation Language DML Can be embedded in other languages

Questions?
In what language UNIX is written? What is aliasing? What is exception handling? What does it mean for a program to be reliable? Which is faster, compiler or interpreter? What does a linker do? 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.

Vous aimerez peut-être aussi