Вы находитесь на странице: 1из 60

BCS2223

Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?

BCS2223 Programming Paradigms


Chapter 01: Introduction

Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

University Malaysia of Computer Science & Engineering

Semester: September 2015

Summary

1/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

2/60

Machine Language
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Programming
Writing instructions that tells the computer what to do.
Processor can understand & execute machine instructions, which
are simply binary numbers
Lowest-level
But very tedious & error-prone for human programmers!
For computers & for processor designers, not for
programmers consumptions!
A machine language program

00001001
10101111
11000110
01011000

11000110
01011000
10101111
00001001

10101111
00001001
01011000
11000110

01011000
11000110
00001001
10101111
3/60

Assembly Language
BCS2223
Programming
Paradigms

Main Improvement
Instruction: Use symbolic name or mnemonic for each opcode

Chapter 01:
Introduction

Data: Use pseudoinstruction for specifying data in a location


Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Low-level Programming language


very close to machine language
Assembler translates assembly language into machine language
An assembly language program

lw
lw
sw
sw

$t0,
$t1,
$t0,
$t1,

0($2)
4($2)
0($2)
4($2)

4/60

High-Level Programming Language


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Strong abstraction from details of computer


Closer to human languages and further from machine
languages
E.g., C++, Java, Python, PHP, . . .

C language is often considered middle level


Bridges gap between low-level languages and high-level
languages (pointer, inline assembly, . . . )

Compiler
Translates high-level programming language into intermediate
or machine language
A high-level programming language program

/* Swap v[k] with v[k+1] */


temp = v[k];
v[k] = v[k+1];
v[k+1] = temp;
5/60

Languages
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

Natural vs Programming
Natural
Communicate among
humans
Write essays
Few write well
300,000 years old
Extremely complex
No formal theory is capable of
describing

Programming
Communicate with
literal-minded machine
Write programs
Few write well
60+ years old
Complex
Based on mathematical
formalisms

Summary

6/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

7/60

Questions & Answers


BCS2223
Programming
Paradigms
Chapter 01:
Introduction

What is the purpose of a programming language?


Specifying algorithm and data
Communicating to other people

Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Establish correctness
Why use anything besides machine code?
Readable, familiar notations
Machine independence (portability)
Availability of program libraries
Consistency checks (data types) during implementation
Dealing with scale
The art of programming is the art of organizing complexity.
Dijkstra, 1972
8/60

Questions & Answers (Cont.)


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Why learn more than one programming language?


Each language encourages thinking about a problem in a
particular way.
Each language provides slightly different functionality.
The language used should match the problem.
No single programming paradigm solves all problems in the
easiest or most efficient way.
Why learn about principles and paradigms of programming
languages?
A programming language is a tool.
Studying the design of a tool leads to better understanding of
its functionality and limitations, and increased competence in
using it.
Basis for lots of other work in computer science.
9/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

10/60

Paradigm
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

Paradigm
An example that serves as pattern or model.
The American Heritage Dictionary of the English Language, Third Edition
A philosophical and theoretical framework of a scientific school or
discipline within which theories, laws, and generalizations and the
experiments performed in support of them are formulated;
A philosophical or theoretical framework of any kind
The Merriam-Websters Collegiate dictionary
http://www.merriam-webster.com/dictionary/paradigm

Summary

11/60

Programming Paradigm
And Related Concepts

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Programming Paradigm
The basic structuring of thought underlying the programming
activity
A pattern that serves as a school of thoughts for programming
of computers
Programming Style
The way we express ourselves in a computer program
Related to elegance or lack of elegance
Programming Technique
Related to an algorithmic idea for solving a particular class of
problems
12/60

Programming Paradigms
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Many programming paradigms have been defined.


Shown below is an overview of the various paradigms according to
Peter Van Roy. (Poster taken from https://www.info.ucl.ac.be/pvr/paradigms.html)
record
Descriptive
declarative
programming

The principal programming paradigms

XML,
Sexpression

Data structures only


Turing equivalent

"More is not better (or worse) than less, just different."


v1.08 2008 by Peter Van Roy

+ procedure

Observable
nondeterminism? Yes No

Firstorder
functional
programming

+ cell (state)

Imperative
programming

Pascal, C
+ closure

Imperative
search
programming

Functional
programming

+ unification
(equality)

Scheme, ML

+ search
Relational & logic
programming

+ byneed
synchron.
Prolog, SQL
Lazy
embeddings
functional
+ solver
programming
Constraint (logic)
Haskell
programming

CLP, ILOG Solver

+ thread
Concurrent
constraint
programming

ADT
functional
programming

+ cell

ADT
imperative
programming

Scheme, ML
Haskell, ML, E
CLU, OCaml, Oz
+ thread
+ single assign.
+ nondeterministic
+ port
choice
(channel)
Monotonic
dataflow
programming
Declarative
concurrent
programming

Nonmonotonic
dataflow
programming
Concurrent logic
programming

Multiagent
dataflow
programming

Oz, Alice, AKL

Pipes, MapReduce

+ thread
+ single assignment

+ byneed
synchronization

Lazy concurrent
constraint
programming

Lazy
dataflow
programming
Lazy
declarative
concurrent
programming

Oz, Alice, Curry

Oz, Alice, Curry

Logic and
constraints

Functional

LIFE, AKL
+ byneed synchronization

Unnamed state (seq. or conc.)


More declarative

(unforgeable constant)

+ continuation
Continuation
programming

Deterministic
logic programming

+ search

SNOBOL, Icon, Prolog

+ name

Oz, Alice, Curry, Excel,


AKL, FGHC, FCP
+ synch. on partial termination
Functional reactive
programming (FRP)
Weak synchronous
programming

FrTime, SL
+ instantaneous computation
Strong synchronous
programming
Esterel, Lustre, Signal

Nondet. state

Dataflow and
message passing

+ port
(channel)

+ cell
(state)

Eventloop
programming

E in one vat
+ thread
Multiagent
programming
Messagepassing
concurrent
programming

Erlang, AKL
+ local cell
Active object
programming
Objectcapability
programming

+ closure

Sequential
objectoriented
programming
Stateful
functional
programming

Java, OCaml
+ thread
Concurrent
objectoriented
programming
Sharedstate
concurrent
programming

Smalltalk, Oz,
Java, Alice
+ log

CSP, Occam,
E, Oz, Alice,
publish/subscribe,
tuple space (Linda)

SQL embeddings

Message passing

Shared state

Software
transactional
memory (STM)

Named state
Less declarative

Explanations
See "Concepts, Techniques, and Models of Computer Programming".
The chart classifies programming paradigms according to their kernel
languages (the small core language in which all the paradigms
abstractions can be defined). Kernel languages are ordered according to
the creative extension principle: a new concept is added when it cannot be
encoded with only local transformations. Two languages that implement
the same paradigm can nevertheless have very different "flavors" for the
programmer, because they make different choices about what
programming techniques and styles to facilitate.
When a language is mentioned under a paradigm, it means that part of
the language is intended (by its designers) to support the paradigm
without interference from other paradigms. It does not mean that there
is a perfect fit between the language and the paradigm. It is not enough
that libraries have been written in the language to support the paradigm.
The languages kernel language should support the paradigm. When
there is a family of related languages, usually only one member of the
family is mentioned to avoid clutter. The absence of a language does
not imply any kind of value judgment.
State is the ability to remember information, or more precisely, to store a
sequence of values in time. Its expressive power is strongly influenced by
the paradigm that contains it. We distinguish four levels of expressiveness,
which differ in whether the state is unnamed or named, deterministic or
nondeterministic, and sequential or concurrent. The least expressive is
functional programming (threaded state, e.g., DCGs and monads:
unnamed, deterministic, and sequential). Adding concurrency gives
declarative concurrent programming (e.g., synchrocells: unnamed,
deterministic, and concurrent). Adding nondeterministic choice gives
concurrent logic programming (which uses stream mergers: unnamed,
nondeterministic, and concurrent). Adding ports or cells, respectively,
gives message passing or shared state (both are named, nondeterministic,
and concurrent). Nondeterminism is important for realworld interaction
(e.g., client/server). Named state is important for modularity.
Axes orthogonal to this chart are typing, aspects, and domainspecificity.
Typing is not completely orthogonal: it has some effect on expressiveness.
Aspects should be completely orthogonal, since they are part of a
programs specification. A domainspecific language should be definable
in any paradigm (except when the domain needs a particular concept).
Metaprogramming is another way to increase the expressiveness of a
language. The term covers many different approaches, from higherorder
programming, syntactic extensibility (e.g., macros), to higherorder
programming combined with syntactic support (e.g., metaobject
protocols and generics), to fullfledged tinkering with the kernel language
(introspection and reflection). Syntactic extensibility and kernel language
tinkering in particular are orthogonal to this chart. Some languages, such
as Scheme, are flexible enough to implement many paradigms in almost
native fashion. This flexibility is not shown in the chart.

13/60

Main Programming Paradigms


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Programming paradigms
Main: Imperative, Object-Oriented, Functional, Logical
Others: Declarative, Procedural, Visual, Symbolic, Meta,
Inductive, Probabilistic, . . .
Evolving!
Some paradigms are subsets of others.
Functional Declarative
Procedural Imperative
Multi-paradigm languages support several programming
paradigms
Challenging to combine concepts from different paradigms in
a harmonious way.
E.g.,
Python: imperative, object-oriented, functional, reflective
Oz: imperative, object-oriented, functional, logic, constraint,
distributed, concurrent

14/60

Main Programming Paradigms


Imperative

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

Imperative: Sequence of state-changing actions.


First do this and next do that
Fits the von Neumann architecture closely
Execution of machine code program occurs in fetch-execute
cycle

Manipulate an abstract machine with:


Variables naming memory locations
Arithmetic and logical operations (+ - * /)
Reference, evaluate, assign operations (= &)
Explicit control flow statements (if else while for)

Key operations: Assignment and Goto

Summary

15/60

Main Programming Paradigms


Imperative (Cont.)

BCS2223
Programming
Paradigms

Sum up twice each number from 1 to N: Fortran

Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?

20

SUM = 0
DO 20 K=1,N
SUM = SUM + 2*K
CONTINUE

Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

16/60

Main Programming Paradigms


Object-Oriented

BCS2223
Programming
Paradigms

Object-Oriented: Communication among abstract objects.

Chapter 01:
Introduction

Data and operations are encapsulated in objects

Levels of
Programming
Languages
Why
Programming
Languages?

Objects interact by means of message passing


Classes are organized in inheritance hierarchies
Key operation: Message passing or Method invocation

Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

17/60

Main Programming Paradigms


Object-Oriented (Cont.)

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Sum up twice each number from 1 to N: C++

class Tool {
int n;
public:
Tool(int n) { this->n = n; }
int sum2();
};
int Tool::sum2() {
int sum = 0;
for (int i=1; i<=n; i++)
sum += 2*i;
return sum;
}
Tool tool(4); tool.sum2();

// Evaluates to 20
18/60

Main Programming Paradigms


Functional

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Functional: Composition of operations on data.


Evaluate an expression and use the resulting value for
something
No named memory locations
Value binding through parameter passing
Key operations: Function application and Function abstraction
Basis in lambda calculus
Sum up twice each number from 1 to N: Lisp

(defun sum2(n)
(loop for i from 1 to n sum (* 2 i))
)
(sum2 4) ; Evaluate to 20
19/60

Main Programming Paradigms


Logic

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods

Logic: Formal logic specification on problem.


Answer a question via search for a solution
Non-procedural
Say what properties and/or characteristics the solution must
have, not how to compute it

Solutions through reasoning process.


Key operation: Unification
Basis in first order predicate logic

Brief History of
Programming
Languages
Summary

20/60

Main Programming Paradigms


Logic (Cont.)

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

Sum up twice each number from 1 to N: Prolog

sum2(0, 0).
sum2(N, S) :N > 0,
N1 is N-1,
sum(N1, S1),
S is S1+2*N.
?- sum2(4, N).
N = 20 ?
yes

Summary

21/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

22/60

Implementation Methods
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages

Compilation
Pure Interpretation
Hybrid Implementation

Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

23/60

Implementation Methods
Compilation

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages

Compilation (aka Ahead-of-time (AOT) Compilation)


Programs are translated by a compiler into machine
language (all at once)
Translation is slow
Especially when enabling (aggressive) optimization, in which
a compiler improves programs by making them smaller or
faster or both.

Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Execution is fast
Especially the target programs have been optimized for
performance.

E.g.,
COBOL, Ada, C, C++.
Android Runtime (ART) (available in Android versions 4.4
KitKat and later): Compiles Dalvik bytecode (which is
compiled from Java) into system-dependent machine
language.
24/60

Implementation Methods
Compilation (Cont.)

BCS2223
Programming
Paradigms

The compilation process.

Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

25/60

Implementation Methods
Pure Interpretation

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods

Pure Interpretation
Programs are interpreted by an interpreter
(one statement at a time)
No translation

Execution is slower
Can be 10 to 100 times slower than
compiled programs

Space requirement is often higher


Machine instructions generally occupy less
space

Brief History of
Programming
Languages

Now rare for traditional high-level languages

Summary

Significant comeback with some Web


scripting languages (E.g., JavaScript, PHP.)

Pure
interpretation.

26/60

Implementation Methods
Hybrid Implementation

BCS2223
Programming
Paradigms
Chapter 01:
Introduction

Hybrid Implementation
Compromise between compilation and pure interpretation
Combines some advantages and drawbacks of both

Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods

A high-level language program is first compiled to an


intermediate language that allows easy interpretation
E.g.,
Perl: Partially compiled to detect errors before interpretation.
Java (early implementation): Compiled to byte code, which is
then interpreted by Java Virtual Machine (JVM). Provides
portability to any machine that is able to execute JVM.

Brief History of
Programming
Languages
Summary

27/60

Implementation Methods
Hybrid Implementation (Cont.)

BCS2223
Programming
Paradigms

Hybrid implementation system.

Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

28/60

Implementation Methods
Hybrid Implementation (Cont.)

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages

Just-in-Time (JIT) Implementation (aka Dynamic Translation)


A high-level language program is first compiled to an
intermediate language; When some fragments of
intermediate language are called, the JIT compiler
dynamically compiles them into machine language.
Similar to the pure hybrid implementation described above,
but compile instead of interpret code fragments when they are
called.

Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

E.g.,
Java (modern compilers). Including Dalvik VM (available in
Android versions 4.4 KitKat and earlier).
Microsoft .NET languages.

Summary

29/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

30/60

Why History?
BCS2223
Programming
Paradigms
Chapter 01:
Introduction

Outlines the evolution of important programming languages.


Will not attempt to describe any language completely
Focus more on the origins, purposes, and contributions

Levels of
Programming
Languages

Why study history of programming languages?

Why
Programming
Languages?

Provides the background necessary to understand practical


and theoretical basis for contemporary language design

Programming
Paradigms

Motivates further study of language design and criteria

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

31/60

Early History
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

2000 B.C., Babylon: Algorithms for calendar computations


300 B.C., Greece: Euclid of Alexandria (Father of Geometry)
expressed greatest common divisor (GCD, aka HCF)
algorithm using iteration.
1842, England: Ada, Countess of Lovelace (18151852)
(First Computer Programmer), wrote worlds first computer
program, for Charles Babbages analytical engine.
Bernoulli numbers (Bn )
program by Ada Lovelace,
where
z

Summary

ez

zn

Bn n! ,

|z | < 2

n=0

32/60

Genealogy of Programming Languages


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods

Genealogy of common high-level


programming languages. Taken
from [Robert16].

Brief History of
Programming
Languages
Summary

33/60

Genealogy of Programming Languages (Cont.)


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Originally appeared in the Wired Magazine. Taken from

http://www.digibarn.com/collections/posters/tongues/.
34/60

Which Programming Language?


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages

Analogy by Prithvi Raj & diagram by Carl Cheo. Get full version from
Summary

http://www.digibarn.com/collections/posters/tongues/.
Lord of the Rings characters to programming languages are included in the following
slides... (Credits go to J. R. R. Tolkien & Prithvi Raj & Carl Cheo)
35/60

Machine Code & Assembly Language


In the Beginning

BCS2223
Programming
Paradigms
Chapter 01:
Introduction

Machine Code:
Only machine code in the beginning (ENIAC, 1946)
Right combination of 1s and 0s to perform some computation

Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Exceptionally tedious work


Assembly Language:
Mnemonics (e.g., ADD, SUB) substituted for the bit pattern of
machine instruction
More manageable, but still difficult for humans
Screenshot from the movie Terminator, 1984.
Assembly code of the immortal 6502 chip (year
1975), which was used in Apple II, is still
powering millions of devices, and will power the
first T-series of Terminators (well, its just a
joke!), . . .

36/60

Fortran, Lisp, COBOL


From Late 1950s

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

FORTRAN, 1954, John Backus (IBM)


FORmula TRANslation
First widely accepted compiled high-level language
For numeric computation and scientific computing
Very popular in computationally intensive areas such as
numerical weather prediction, finite element analysis.

Lisp, 1956, John McCarthy (Stanford)


LISt Processor
Pioneered functional programming
Popular for Artificial Intelligence

COBOL, 1959, Grace Murray Hopper & Department of


Defense (DoD) committee.
COmmon Business Oriented Language
For business data processing
English-like syntax (English names for arithmetic operators)
Still the most widely used business applications language

These are oldest languages that are still used today.

37/60

ALGOL
First Step Toward Sophistication

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

ALGOL 60, 1958, International committee


ALGOrithmic Language
Result of efforts to design a universal programming
language for scientific applications
Standard way to publish algorithms for over 20 years
First language whose syntax was formally defined
(Backus-Naur Form)
ALGOL 68, 1963, A. van Wijngaarden, et al.
From continued development, but not a superset, of
ALGOL 60
Orthogonal language design
Never achieved widespread use
Strong influence on most subsequent imperative
languages, e.g., Simula, CPL, BCPL, Pascal, Ada, C
38/60

BASIC
Beginning of Timesharing

BCS2223
Programming
Paradigms

BASIC, 1964, John George Kemeny and Thomas Eugene Kurtz


Beginners All-purpose Symbolic Instruction Code

Chapter 01:
Introduction

Designed to be easy to learn and use for non-science


students

Levels of
Programming
Languages

First widely used language with timesharing

Why
Programming
Languages?

Enjoyed widespread use on microcomputers in late 1970s


and early 1980s

Programming
Paradigms

Criticized for poor program structure

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Current popular dialect: Visual Basic


Example of BASIC program

10
20
30
40
50
60
70
80

PRINT "Table of Squares"


PRINT
PRINT "How many values would you like?"
INPUT NUM
FOR I=1 TO NUM
PRINT I, I*I
NEXT I
END
39/60

SIMULA 67
Beginning of Data Abstraction

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

SIMULA 67, 1967, Nygaard and Dahl


For simulation
Considered the first OOP language
Never achieved widespread use, but some constructs it
introduced make it historically important
Coroutines: a kind of subprogram
Concept of data abstraction
Objects, classes, inheritance, virtual methods
Example of SIMULA 67 program

Begin
Class Glyph;
Virtual: Procedure print Is Procedure print;
Begin
End;
Glyph Class Char (c);
Character c;
Begin
Procedure print;
OutChar(c);
End;
(...omitted...)
End;

40/60

Pascal
Simplicity by Design

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Pascal, 1969, Niklaus Wirth (was in ALGOL 68 committee)


For teaching structured programming
Most widely used language for teaching programming from
mid-1970s to late 1990s.
Example of Pascal program

PROGRAM Test;
{* Calculate Area of Circle *}
VAR
radius: REAL;
FUNCTION CircleArea(r : REAL): REAL;
BEGIN
CircleArea := 3.1416 * r * r;
END;
BEGIN
WRITE(Enter radius: );
READLN(radius);
WRITE(Area of circle with radius , radius:3:1, : );
area := CircleArea(radius);
WRITELN(area:5:2);
END.

Can language designed for teaching be used for production?

41/60

Prolog
Programming Based on Logic

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?

Prolog, 1972, Colmerauer


Programming logic
For Artificial Intelligence (AI) applications
Pioneered logic programming, and remains popular
Comparatively inefficient
Example of Prolog program

Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

eats(fred, oranges).
eats(tony, apples).
eats(john, apples).
?- eats(fred, oranges).
yes
?- eats(Who, apples).
Who = tony ? ;
Who = john ? ;
no

Prolog was chosen to use in The Fifth Generation Computer Project (FGCS).

What happened to FGCS?

42/60

C
Portable Systems Language

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

C, 1972, Dennis Ritchie (Bell Labs)


For systems programming
Used to re-implement Unix operating system
Has also been used in many application areas
Efficient code generation

Has since become the most widely used


programming languages of all time
Influence so many later languages! (Such as?)
Spirit of C, from Rationale for the C99 standard (available here)
Trust the programmer
Dont prevent the programmer from doing what needs to be done
Keep the language small and simple
Provide only one way to do an operation
Make it fast, even if it is not guaranteed to be portable
43/60

Smalltalk
Object-Oriented Programming

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Smalltalk, 1972, Alan Kay


First full implementation of object-oriented language
(data abstraction, inheritance, dynamic binding)
Pioneered the graphical user interface (GUI) design
Model-View-Contoller (MVC) pattern (now a must for iOS
Apps Development)

Influenced many object-oriented languages


Example of Smalltalk program (code snippet by Ralph Johnson)

"This is a comment."
"Syntax is rather minimalist. Only six keywords are reserved in Smalltalk!"
exampleWithNumber: x
| y |
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a "a" 1 1.0)
do: [ :each |
Transcript show: (each class name);
show: ].
x < y
44/60

Ada
Largest Design Effort in History

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Ada, 1977, DoD committee


Historical Background
More than 450 programming languages
used for DoD projects
DoD decided to develop single
high-level language for embedded and
real-time systems
Most extensive and expensive
language design effort (hundreds of
people, much money, about eight years)

Extremely strong typing, explicit


concurrency, exception handling,
generics.

Watercolor portrait of Ada King,


Countess of Lovelace.
Artist: Alfred Edward Chalon.
Source: https://commons.

wikimedia.org/wiki/File:
Ada_Lovelace_portrait.jpg).
Public Domain.

45/60

Ada (Cont.)
Largest Design Effort in History

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Popularity suffered
DoD no longer requires its use
Widespread acceptance of C++ for OOP
Most serious criticism: too large and too complex

Still widely used in both commercial and defense avionics, air


traffic control, rail transportation, and other areas.
Later versions: Ada 95, Ada 2005, Ada 2012.
Example of Ada program

(...omitted...)
package body CharStak is
Maximum_Size : constant := 25;
Stack_List : STRING(1..Maximum_Size);
Top_Of_Stack : INTEGER := 0;
function Is_Empty return BOOLEAN is
begin
return Top_Of_Stack = 0;
end Is_Empty;
(...omitted...)
46/60

C++
Combining Imperative and Object-Oriented Features

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

C++, 1985, Bjarne Stroustrup (Bell Labs)


The name signifies the evolutionary nature of
the changes from C. Stroustrup
For general-purpose programming. Goals:
Programs could be organized with classes and
inheritance
Little or no performance penalty relative to C
Backward compatible to C

Language
Implementation
Methods

Large and complex, in part because it supports


both imperative and OO programming

Brief History of
Programming
Languages

Rapidly grew in popularity, along with OOP

Summary

47/60

Java
Imperative-Based Object-Oriented Language

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Java, 1995, Gosling (Sun Microsystems).


Based on C++
Significantly simplified (exclude struct,
union, pointer arithmetic, many assignment
coercions, some unsafe features.)
Supports only OOP
Has references, but not pointers

Portable; Cross-platform
Java Virtual Machine concept
JIT compilers

Very popular
Client-server web applications
Most Android applications are written in
Java-like language (Why Java-like?)

48/60

Scripting Languages
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Early scripting languages were used by putting a list of


commands, called a script, in a file to be interpreted.
Now frequently used loosely to refer to dynamic high-level
general-purpose languages
Dynamic languages do many tasks at runtime where static
languages would do them during compilation
Behaviors include extension of program, by adding new code,
by extending objects and definitions, or by modifying the type
system.

Common characteristics of many scripting languages used


today
Support imperative, object-oriented, and functional paradigms
While program can be interpreted, compilers are sometimes
developed to improve performance of program execution

49/60

Scripting Languages (Cont.)


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

sh (for shell)
First of scripting languages
Collection of commands that were interpreted
as calls to system subprograms
Perl, 1987, Larry Wall
Currently widely used as a UNIX system
administration tool
JavaScript, 1995, Brendan Eich
Very popular as client-side HTML-embedded
scripting language
Only language that the most popular browsers
share support for

50/60

Scripting Languages (Cont.)


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

PHP, 1995, Rasmus Lerdorf


PHP: Hypertext Preprocessor
Recursive backronym
PHP originally stood for
Personal Home Page

Very popular as server-side


HTML-embedded scripting
language
Python, 1991, Guido van Rossum
General-purpose
Used by Google, YouTube, Yahoo!,
CERN, NASA, . . .

51/60

Scripting Languages (Cont.)


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Ruby, 1995, Yukihiro Matz Matsumoto


Thoroughly object-oriented
All data are objects
Most operators, like methods, can be redefined

Lua, 1993, Roberto Ierusalimschy, Luiz Henrique de


Figueiredo, and Waldemar Celes:
Easily extendable

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

52/60

Objective-C
Combining Imperative and Object-Oriented

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages

Objective-C, 1983, Brad Cox and Tom Love:


C plus support for OOP based on Smalltalk
Uses Smalltalks method calling syntax
Used by Apple for system programming

Why
Programming
Languages?

Example of Objective-C program

Programming
Paradigms

@implementation Process

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

# import "Process.h"

- (int)process:(SEL)sel args:(arglist_t) args {


if ([client respondsToSelector:sel]) {
return [client performv:sel args:args];
} else {
return [self error:"Client does not respond"];
}
}
@end

53/60

C]
Flagship .NET Language

BCS2223
Programming
Paradigms
Chapter 01:
Introduction

C] (or C#), 2000, Microsoft:


Pronounced as C Sharp
Name inspired by musical notation

Levels of
Programming
Languages
Why
Programming
Languages?

Part of the Microsoft .NET development platform


Evolving rapidly
Example of C] program

Programming
Paradigms

using System;

Language
Implementation
Methods

class Example
{
public int Number { get; set; }
}

Brief History of
Programming
Languages
Summary

class Program
{
static void Main()
{
Example example = new Example();
example.Number = 168;
Console.WriteLine(example.Number);
}
}

54/60

Go
by Google Inc.

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?

Go (aka golang), 2007, Robert Griesemer, Rob Pike,


and Ken Thompson (designer of B, the predecessor of C;
codesigner with Dennis Ritchie of UNIX):
Aim to overcome various issues with C++
Syntax loosely derived from that of C
Static typing, garbage collection, type safety,
concurrent, dynamic-typing; NO OOP

Image taken from


golang.org.

Programming
Paradigms
Example of Go program
Language
Implementation
Methods

package main
import "fmt"

Brief History of
Programming
Languages
Summary

func main() {
nums := []int{2, 3, 4}
sum := 0
for _, num := range nums {
sum += num
}
fmt.Println("sum:", sum)
}
55/60

Swift
Objective-C without the C Apple Inc.

BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Swift, 2014, Chris Lattner and Apple Inc.:


Designed to work with Apples Cocoa and
Cocoa Touch Frameworks, and lots of existing
Objective-C programs for Apple products
Meant to be more concise and resilient to
erroneous code.
It was announced that Swift 2 would become
open source in late 2015.
Example of Swift program

func convert() -> [Int: Double] {


let conversions = [3.0, 4.0, 5.0]
var value = [Int: Double]()
for conversion in conversions {
let vv = Int(3.5 * conversion)
value[vv] = calc(conversion)
}
return value
}
56/60

Miscellaneous
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

Document Markup Languages


For processing, definition, and presentation of text
E.g., HyperText Markup Language (HTML), eXtensible
Markup Language (XML), TEX, LATEX

Markup/Programming Hybrid Languages


Markup Language in which some of the elements can specify
programming actions
E.g., Extensible Stylesheet Language Transformations
(XSLT), Java Server Pages (JSP)
Example of LATEX document

\documentclass[a4paper]{article}
\begin{document}
\section{Hello!}
% This makes a section title
Hello, \textbf{World}!
\end{document}

This set of lecture notes is prepared by using LAT X.


E

57/60

Programing Language Popularity


BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages

Difficult to determine popularity of programming languages


Some languages are very popular for particular kinds of
applications

Why
Programming
Languages?
Programming
Paradigms
Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

The TIOBE index (a programming language popularity index) graph from Jun-2002 to
Sep-2015. Available from

http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html.

58/60

Table of Contents
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Levels of Programming Languages

Why Programming Languages?

Programming Paradigms

Language Implementation Methods

Brief History of Programming Languages

Summary

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

59/60

Summary
BCS2223
Programming
Paradigms
Chapter 01:
Introduction
Levels of
Programming
Languages
Why
Programming
Languages?
Programming
Paradigms

Introduced & investigated:


Levels of Programming Languages
Programming Paradigms
Language Implementation Methods
Important Programming Languages
In-depth discussion to follow in upcoming chapters.

Language
Implementation
Methods
Brief History of
Programming
Languages
Summary

60/60

Вам также может понравиться