evaluation of programming languages
TRANSCRIPT
-
7/31/2019 Evaluation of Programming Languages
1/29
Evaluation of ProgrammingLanguages
Asst. Prof. Dr. Ahmet Sayar
Spring-2012
Kocaeli University
Computer Engineering Department
Principles of Programming
Languages
-
7/31/2019 Evaluation of Programming Languages
2/29
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 (adialect of LISP)
-
7/31/2019 Evaluation of Programming Languages
3/29
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
-
7/31/2019 Evaluation of Programming Languages
4/29
Readability
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:
In C:
while (inc 20) {
while (sum 100) {
sum+= inc;
}
inc++;}
-
7/31/2019 Evaluation of Programming Languages
5/29
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
-
7/31/2019 Evaluation of Programming Languages
6/29
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, well-definedness
-
7/31/2019 Evaluation of Programming Languages
7/29
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
-
7/31/2019 Evaluation of Programming Languages
8/29
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 toCPU
Basis for imperative languages Variables model memory cells
Assignment statements model piping
Iteration is efficient
-
7/31/2019 Evaluation of Programming Languages
9/29
Von Neumann Architecture
-
7/31/2019 Evaluation of Programming Languages
10/29
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
-
7/31/2019 Evaluation of Programming Languages
11/29
Programming Paradigms
1. Imperative
Structured Programming
Object Oriented Programming
Distributed Programming
2. Declarative
Functional Programming
Logic Programming
Database Languages
-
7/31/2019 Evaluation of Programming Languages
12/29
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 wayof thinking
C, Fortran, Pascal, Pascal
-
7/31/2019 Evaluation of Programming Languages
13/29
2. Declarative Languages
Expresses whatthe program should
accomplish without prescribing howto 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
-
7/31/2019 Evaluation of Programming Languages
14/29
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 GOTOstatement.
Well known examples: C, Fortran, PL/I, Pascal, Cobol, Ada.
-
7/31/2019 Evaluation of Programming Languages
15/29
1.2. Object Oriented Programming
An abstraction and generalization of imperative programming.
Involves collections of objects each with a state and a set ofoperations to transform the state.
Focuses on data rather than on control.
As in the real world, objects interact so object-orientedprogramming uses the metaphor of message passing tocapture the interaction of objects.
Encapsulate data objects with processing
Inheritance and dynamic type binding
Grew out of imperative languages
C++, Java
-
7/31/2019 Evaluation of Programming Languages
16/29
Object Oriented Programming
-
7/31/2019 Evaluation of Programming Languages
17/29
1.3. Distributed Programming
Distributed computing is a field of computer science that studiesdistributed systems.
A distributed system consists of multiple autonomous computers thatcommunicate through a computer network
A computer program that runs in a distributed system is called a
distributed program, and distributed programming is the process ofwriting such programs
There are several autonomous computational entities, each of which hasits own local memory.
The entities communicate with each other by message passing.
The computational entities are called computers or nodes.
WHY Distributed systems ?
-
7/31/2019 Evaluation of Programming Languages
18/29
Distributed Programming
-
7/31/2019 Evaluation of Programming Languages
19/29
2.1. Functional Programming 1
Functional programming is a style of programming in whichthe basic method of computation is the application offunctions 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
-
7/31/2019 Evaluation of Programming Languages
20/29
Functional Programming Ex: Scheme 2
In a functional programming language, certain functions, calledprimitive functions or just primitive, are defined as part of thelanguage. Other functions can be defined and named by theprogrammer. To define the doubling function using Scheme youcould say
(define (double x)
( * 2 x)
Scheme responds immediately to a function invocation bydisplaying the result so the following will occur using thenumbers 5 and 7.
(double 5)
10(double 7)
14
What is the difference between a mathematical function and thenotion of a function used in imperative programminglanguage?
-
7/31/2019 Evaluation of Programming Languages
21/29
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
-
7/31/2019 Evaluation of Programming Languages
22/29
Functional Programming - 4
Common functional programming language
and its gcd application is given below
-
7/31/2019 Evaluation of Programming Languages
23/29
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
-
7/31/2019 Evaluation of Programming Languages
24/29
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
-
7/31/2019 Evaluation of Programming Languages
25/29
Logic Programming - 3
1-25
-
7/31/2019 Evaluation of Programming Languages
26/29
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 Prologprogram was written for American history. The example consisted of which U.S.presidents were in office when certain events occurred and in the chronologyorder 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).
-
7/31/2019 Evaluation of Programming Languages
27/29
Exercises
?-before(lincoln, fdr)
?-president (jefferson, lewis_and_clark)
?-before(first_moon_landing ,
cuban_missle_crisis)
-
7/31/2019 Evaluation of Programming Languages
28/29
2.3. Database Programming
SQL
Definition Language DDL
Manipulation Language DML
Can be embedded in other languages
-
7/31/2019 Evaluation of Programming Languages
29/29
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.