You are on page 1of 17

Programming 2 (PR2)

Lecture 1
Overview of Programming Languages
Lecture outline

Why so many languages?

Programming language (PL) features

What makes a good PL?

Why study PLs?

PL spectrum

Duc M. L. PR2 2
1 Why so many languages?

Evolution

Special purposes

Personal perference

Duc M. L. PR2 3
2 PL features

Expressive power

Ease of use

Ease of implementation

Standardisation

Open source

Excellent compilers

Economics, Patronage, and Inertia

Duc M. L. PR2 4
PL features

Expressive power ●
write clear, concise

Ease of use & maintainable code

abstraction

Ease of implementation

Standardisation

Open source

Excellent compilers

Economics, Patronage, and Inertia

Duc M. L. PR2 5
PL features

Expressive power

Ease of use ●
low learning curve

Ease of implementation for beginning
programmers

Standardisation

Open source

Excellent compilers

Economics, Patronage, and Inertia

Duc M. L. PR2 6
PL features

Expressive power

Ease of use

Ease of implementation ●
suitable for average

Standardisation machines

Open source

accessible (e.g. free
for educational use)

Excellent compilers

Economics, Patronage, and Inertia

Duc M. L. PR2 7
A good PL is a compromise!

Between the desires of programmer and PL
implementor

Programmer: PL user

language = means of expressing algorithms

main concern: conceptual clarity

PL implementor: PL designer/creator

language = means of instructing computers

main concern: implementation efficiency

To achieve both concerns require making
compromises!
Duc M. L. PR2 8
Donald E. Knuth (1938-)

programming be regarded as the art of telling


another human being what one wants the
computer to do

Duc M. L. PR2 9
3 Why study PLs?

Know obscure features

Understand different ways of expressing

Help choose a PL for a given task

Make it easier to learn new PLs

Make good use of common development tools:

debuggers, assemblers, linkers

Add new useful features to a language

Make better use of language technology

Duc M. L. PR2 10
4 PL spectrum

declarative imperative

template- von object-


functional data flow logic scripting
based neumann oriented

Lisp/Scheme Id, XSL Prolog, C, Perl, Smalltalk,


ML Val T spreadsheet Ada, Python, Eiffel,
Haskell Fortran PHP Java

based on model of computation

Duc M. L. PR2 11
Comparison

Declarative language:

focus more on programmer's than implementor's view

describe what rather than how

Imperative language:

describe how a program is executed

But the distinctions are not absolute:

e.g. functional language can also have object-oriented
feature

Duc M. L. PR2 12
Von Neumann language

Computation:

modification of variables

Side effects:

value of memory is changed in statements

Duc M. L. PR2 13
Example: Gcd

int gcd(int a, int b) { // C


while (a != b) {
if (a > b) a = a - b;
else b = b - a;
}
return a;
}

Duc M. L. PR2 14
Example: Gcd

static int gcd(int a, int b) { // Java


while (a != b) {
if (a > b) a = a - b;
else b = b - a;
}
return a;
}

Duc M. L. PR2 15
Object oriented language

Computation:

interactions among semi-independent objects

Object has internal state and procedures

Duc M. L. PR2 16
Summary

Many PLs exist because of evolution, purpose,
preference

A good PL strikes a balance between
conceptual clarity and implementation
efficiency

PL spectrum includes a categorisation of PLs
into declarative and imperative forms

Study PLs help raise the awareness of and
choose suitable PL(s) for a given task

Duc M. L. PR2 17

You might also like