20150928120955C01_introduction
-
Upload
mohammad-asyraf -
Category
Documents
-
view
218 -
download
3
description
Transcript of 20150928120955C01_introduction
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
1/60
BCS2223 Programming Paradigms
Chapter 01: Introduction
University Malaysia of Computer Science & Engineering
Semester: September 2015
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
2/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
3/60
Machine Language
Programming
Writing instructions that tells the computer what to do.
Processor can understand & execute machine instructions, whichare simply binary numbers
Lowest-level
But very tedious & error-prone for human programmers!
For computers & for processor designers, not forprogrammers’ consumptions!
A machine language program
00001001 11000110 10101111 0101100010101111 01011000 00001001 1100011011000110 10101111 01011000 0000100101011000 00001001 11000110 10101111
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
4/60
Assembly Language
Main Improvement
Instruction: Use symbolic name or mnemonic for each opcode
Data: Use pseudoinstruction for specifying data in a location
Low-level Programming language
very ‘close’ to machine language
Assembler translates assembly language into machine language
An assembly language program
lw $t0, 0($2)lw $t1, 4($2)sw $t0, 0($2)sw $t1, 4($2)
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
5/60
High-Level Programming Language
Strong abstraction from details of computer‘Closer’ to human languages and ‘further’ from machinelanguages
E.g., C++, Java, Python, PHP, . . .C language is often considered “middle level”
Bridges gap between low-level languages and high-levellanguages (pointer, inline assembly, . . . )
CompilerTranslates high-level programming language into intermediateor 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;
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
6/60
Languages
Natural vs Programming
Natural ProgrammingCommunicate amonghumans
Communicate withliteral-minded machine
Write essays Write programsFew write well Few write well300,000 years old 60+ years oldExtremely complex ComplexNo formal theory is capable ofdescribing
Based on mathematicalformalisms
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
7/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
8/60
Questions & Answers
What is the purpose of a programming language?
Specifying algorithm and data
Communicating to other people
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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
9/60
Questions & Answers (Cont.)
Why learn more than one programming language?
Each language encourages thinking about a problem in aparticular way.
Each language provides slightly different functionality.
The language used should ‘match’ the problem.
No single programming paradigm solves all problems in theeasiest or most efficient way.
Why learn about principles and paradigms of programminglanguages?
A programming language is a tool.
Studying the design of a tool leads to better understanding ofits functionality and limitations, and increased competence inusing it.
Basis for lots of other work in computer science.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
10/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
11/60
Paradigm
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 ordiscipline within which theories, laws, and generalizations and theexperiments performed in support of them are formulated;A philosophical or theoretical framework of any kind
— The Merriam-Webster’s Collegiate dictionary
http://www.merriam-webster.com/dictionary/paradigm
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
12/60
Programming ParadigmAnd Related Concepts
Programming Paradigm
The basic structuring of thought underlying the programmingactivity
A pattern that serves as a school of thoughts for programmingof 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 ofproblems
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
13/60
Programming Paradigms
Many programming paradigms have been defined.Shown below is an overview of the various paradigms according toPeter Van Roy. (Poster taken from https://www.info.ucl.ac.be/˜pvr/paradigms.html)
nondeterminism?Observable
Yes No
More declarative Less declarativeNamed stateUnnamed state (seq. or conc.)
(equality)+ name
+ by−need synchronization
+ by−needsynchronization
+ thread
+ continuation
Lazy concurrent
object−orientedConcurrent
programming
Shared−stateconcurrent
programming
Softwaretransactional
memory (STM)
Sequentialobject−orientedprogramming
Statefulfunctional
programming
programmingImperative
Lazydeclarativeconcurrent
programming
programming
Lazydataflow
Concurrentconstraint
programming
constraintprogramming
Constraint (logic)programming
Relational & logicprogramming
Deterministiclogic programming
synchron.+ by−need + thread
+ single assign.
Haskell
Lazyfunctional
programming
Monotonicdataflow
programming
Declarativeconcurrent
programming
ADTfunctional
programming
ADTimperative
programming
Functionalprogramming
First−orderfunctional
programming
Descriptivedeclarative
programming
Imperativesearch
programming
Event−loopprogramming
Multi−agentprogramming
Message−passingconcurrent
programming
Data structures only
Turing equivalent
+ cell (state)
+ unification
Dataflow and
Oz, Alice, Curry Oz, Alice, Curry
CLU, OCaml, Oz
E in one vat
Continuationprogramming
Logic and
constraints message passing Message passing Shared state
v1.08 © 2008 by Peter Van Roy
+ nondeterministic
(channel)
Oz, Alice, Curry, Excel,
AKL, FGHC, FCP
+ synch. on partial termination
FrTime, SL
+ instantaneous computation
Strong synchronousprogramming
Esterel, Lustre, Signal
Functional reactiveprogramming (FRP)
Weak synchronousprogramming
Pipes, MapReduce
Nondet. state
See "Concepts, Techniques, and Models of Computer Programming".
Explanations
Erlang, AKL
CSP, Occam,E, Oz, Alice,
publish/subscribe,tuple space (Linda)
choice
Nonmonotonicdataflow
programming
Concurrent logicprogramming
Oz, Alice, AKL
+ port
Multi−agentdataflow
programming
The chart classifies programming paradigms according to their kernel
abstractions can be defined). Kernel languages are ordered according tothe creative extension principle: a new concept is added when it cannot beencoded with only local transformations. Two languages that implement
programmer, because they make different choices about whatprogramming techniques and styles to facilitate.
the same paradigm can nevertheless have very different "flavors" for the
languages (the small core language in which all the paradigm’s
without interference from other paradigms. It does not mean that thereis a perfect fit between the language and the paradigm. It is not enoughthat libraries have been written in the language to support the paradigm.The language’s kernel language should support the paradigm. Whenthere is a family of related languages, usually only one member of the family is mentioned to avoid clutter. The absence of a language doesnot imply any kind of value judgment.
When a language is mentioned under a paradigm, it means that part ofthe language is intended (by its designers) to support the paradigm
Typing is not completely orthogonal: it has some effect on expressiveness. Axes orthogonal to this chart are typing, aspects, and domain−specificity.
program’s specification. A domain−specific language should be definablein any paradigm (except when the domain needs a particular concept).
Aspects should be completely orthogonal, since they are part of a
native fashion. This flexibility is not shown in the chart. as Scheme, are flexible enough to implement many paradigms in almosttinkering in particular are orthogonal to this chart. Some languages, such(introspection and reflection). Syntactic extensibility and kernel languageprotocols and generics), to full−fledged tinkering with the kernel language programming combined with syntactic support (e.g., meta−object programming, syntactic extensibility (e.g., macros), to higher−order language. The term covers many different approaches, from higher−order Metaprogramming is another way to increase the expressiveness of a
sequence of values in time. Its expressive power is strongly influenced bythe paradigm that contains it. We distinguish four levels of expressiveness,
State is the ability to remember information, or more precisely, to store a
which differ in whether the state is unnamed or named, deterministic ornondeterministic, and sequential or concurrent. The least expressive isfunctional programming (threaded state, e.g., DCGs and monads:unnamed, deterministic, and sequential). Adding concurrency givesdeclarative concurrent programming (e.g., synchrocells: unnamed,deterministic, and concurrent). Adding nondeterministic choice givesconcurrent logic programming (which uses stream mergers: unnamed,
(e.g., client/server). Named state is important for modularity.
nondeterministic, and concurrent). Adding ports or cells, respectively,gives message passing or shared state (both are named, nondeterministic,and concurrent). Nondeterminism is important for real−world interaction+ local cell
Active objectprogramming
Object−capabilityprogramming
Java, OCaml
+ closure
embeddings
+ solver
LIFE, AKL
CLP, ILOG Solver
+ thread+ single assignment
+ thread
Smalltalk, Oz,
+ thread
Java, Alice
+ log
+ cell(state)
Functional
SQL embeddings
Prolog, SQL
+ search
record
XML,S−expression
The principal programming paradigms"More is not better (or worse) than less, just different."
Haskell, ML, E
(unforgeable constant)
+ cell
Scheme, ML
+ procedure
+ closurePascal, C
SNOBOL, Icon, Prolog
+ search
(channel)+ port
Scheme, ML
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
14/60
Main Programming Paradigms
Programming paradigmsMain: Imperative, Object-Oriented, Functional, LogicalOthers: Declarative, Procedural, Visual, Symbolic, Meta,Inductive, Probabilistic, . . .Evolving!Some paradigms are subsets of others.
Functional ⊂ DeclarativeProcedural ⊂ Imperative
Multi-paradigm languages support several programmingparadigms
Challenging to combine concepts from different paradigms ina harmonious way.E.g.,
Python: imperative, object-oriented, functional, reflectiveOz: imperative, object-oriented, functional, logic, constraint,distributed, concurrent
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
15/60
Main Programming ParadigmsImperative
Imperative: Sequence of state-changing actions.
First do this and next do thatFits the von Neumann architecture closely
Execution of machine code program occurs in fetch-executecycle
Manipulate an abstract machine with:Variables naming memory locationsArithmetic and logical operations (+ - * /)Reference, evaluate, assign operations (= &)Explicit control flow statements (if else while for)
Key operations: Assignment and “Goto”
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
16/60
Main Programming ParadigmsImperative (Cont.)
Sum up twice each number from 1 to N: FortranSUM = 0DO 20 K=1,NSUM = SUM + 2*K
20 CONTINUE
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
17/60
Main Programming ParadigmsObject-Oriented
Object-Oriented: Communication among abstract objects.
Data and operations are encapsulated in objects
Objects interact by means of message passing
Classes are organized in inheritance hierarchies
Key operation: Message passing or Method invocation
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
18/60
Main Programming ParadigmsObject-Oriented (Cont.)
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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
19/60
Main Programming ParadigmsFunctional
Functional: Composition of operations on data.
Evaluate an expression and use the resulting value forsomething
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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
20/60
Main Programming ParadigmsLogic
Logic: Formal logic specification on problem.
Answer a question via search for a solutionNon-procedural
Say what properties and/or characteristics the solution musthave, not how to compute it
Solutions through reasoning process.
Key operation: Unification
Basis in first order predicate logic
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
21/60
Main Programming ParadigmsLogic (Cont.)
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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
22/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
23/60
Implementation Methods
Compilation
Pure Interpretation
Hybrid Implementation
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
24/60
Implementation MethodsCompilation
Compilation (aka Ahead-of-time (AOT) Compilation)
Programs are translated by a compiler into machinelanguage (all at once)Translation is slow
Especially when enabling (aggressive) optimization, in whicha compiler improves programs by making them smaller orfaster or both.
Execution is fastEspecially the target programs have been optimized forperformance.
E.g.,COBOL, Ada, C, C++.Android Runtime (ART) (available in Android versions 4.4“KitKat” and later): Compiles Dalvik bytecode (which iscompiled from Java) into system-dependent machinelanguage.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
25/60
Implementation MethodsCompilation (Cont.)
The compilation process.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
26/60
Implementation MethodsPure Interpretation
Pure Interpretation
Programs are interpreted by an interpreter(one statement at a time)
No translation
Execution is slowerCan be 10 to 100 times slower thancompiled programs
Space requirement is often higherMachine instructions generally occupy lessspace
Now rare for traditional high-level languages
Significant comeback with some Webscripting languages (E.g., JavaScript, PHP.)
Pureinterpretation.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
27/60
Implementation MethodsHybrid Implementation
Hybrid Implementation
Compromise between compilation and pure interpretationCombines some advantages and drawbacks of both
A high-level language program is first compiled to anintermediate language that allows easy interpretationE.g.,
Perl: Partially compiled to detect errors before interpretation.Java (early implementation): Compiled to byte code, which isthen interpreted by Java Virtual Machine (JVM). Providesportability to any machine that is able to execute JVM.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
28/60
Implementation MethodsHybrid Implementation (Cont.)
Hybrid implementation system.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
29/60
Implementation MethodsHybrid Implementation (Cont.)
Just-in-Time (JIT) Implementation (aka Dynamic Translation)
A high-level language program is first compiled to anintermediate language; When some fragments ofintermediate language are called, the JIT compilerdynamically compiles them into machine language.
Similar to the ‘pure’ hybrid implementation described above,but compile instead of interpret code fragments when they arecalled.
E.g.,Java (modern compilers). Including Dalvik VM (available inAndroid versions 4.4 “KitKat” and earlier).Microsoft .NET languages.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
30/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
31/60
Why History?
Outlines the evolution of important programming languages.
Will not attempt to describe any language completely
Focus more on the origins, purposes, and contributions
Why study history of programming languages?
Provides the background necessary to understand practicaland theoretical basis for contemporary language design
Motivates further study of language design and criteria
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
32/60
Early History
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 (1815–1852)(First Computer Programmer), wrote world’s first computerprogram, for Charles Babbage’s analytical engine.
Bernoulli numbers (Bn)program by Ada Lovelace,where
zez −1
=∞
∑n=0
Bnzn
n!, |z|< 2π
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
33/60
Genealogy of Programming Languages
Genealogy of common high-levelprogramming languages. Takenfrom [Robert16].
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
34/60
Genealogy of Programming Languages (Cont.)
Originally appeared in the Wired Magazine. Taken from
http://www.digibarn.com/collections/posters/tongues/.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
35/60
Which Programming Language?
Analogy by Prithvi Raj & diagram by Carl Cheo. Get full version fromhttp://www.digibarn.com/collections/posters/tongues/.
Lord of the Rings characters to programming languages are included in the followingslides... (Credits go to J. R. R. Tolkien & Prithvi Raj & Carl Cheo)
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
36/60
Machine Code & Assembly LanguageIn the Beginning
Machine Code:
Only machine code in the beginning (ENIAC, 1946)
Right combination of 1’s and 0’s to perform some computation
Exceptionally tedious work
Assembly Language:
Mnemonics (e.g., ADD, SUB) substituted for the bit pattern ofmachine instruction
More manageable, but still difficult for humans
Screenshot from the movie Terminator, 1984.Assembly code of the ‘immortal’ 6502 chip (year1975), which was used in Apple II, is stillpowering millions of devices, and will power thefirst T-series of Terminators (well, it’s just ajoke!), . . .
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
37/60
Fortran, Lisp, COBOLFrom Late 1950s
FORTRAN, 1954, John Backus (IBM)FORmula TRANslationFirst widely accepted compiled high-level languageFor numeric computation and scientific computingVery popular in computationally intensive areas such asnumerical weather prediction, finite element analysis.
Lisp, 1956, John McCarthy (Stanford)LISt ProcessorPioneered functional programmingPopular for Artificial Intelligence
COBOL, 1959, Grace Murray Hopper & Department ofDefense (DoD) committee.
COmmon Business Oriented LanguageFor business data processingEnglish-like syntax (English names for arithmetic operators)Still the most widely used business applications language
These are oldest languages that are still used today.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
38/60
ALGOLFirst Step Toward Sophistication
ALGOL 60, 1958, International committee
ALGOrithmic Language
Result of efforts to design a universal programminglanguage 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, ofALGOL 60
Orthogonal language design
Never achieved widespread use
Strong influence on most subsequent imperativelanguages, e.g., Simula, CPL, BCPL, Pascal, Ada, C
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
39/60
BASICBeginning of Timesharing
BASIC, 1964, John George Kemeny and Thomas Eugene KurtzBeginner’s All-purpose Symbolic Instruction CodeDesigned to be easy to learn and use for non-sciencestudentsFirst widely used language with timesharingEnjoyed widespread use on microcomputers in late 1970sand early 1980sCriticized for poor program structureCurrent popular dialect: Visual Basic
Example of BASIC program
10 PRINT "Table of Squares"20 PRINT30 PRINT "How many values would you like?"40 INPUT NUM50 FOR I=1 TO NUM60 PRINT I, I*I70 NEXT I80 END
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
40/60
SIMULA 67Beginning of Data Abstraction
SIMULA 67, 1967, Nygaard and DahlFor simulationConsidered the first OOP languageNever achieved widespread use, but some constructs itintroduced make it historically important
Coroutines: a kind of subprogramConcept of data abstractionObjects, classes, inheritance, virtual methods
Example of SIMULA 67 program
BeginClass Glyph;
Virtual: Procedure print Is Procedure print;BeginEnd;
Glyph Class Char (c);Character c;
BeginProcedure print;
OutChar(c);End;(...omitted...)
End;
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
41/60
PascalSimplicity by Design
Pascal, 1969, Niklaus Wirth (was in ALGOL 68 committee)
For teaching structured programming∗
Most widely used language for teaching programming frommid-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;
BEGINWRITE(’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?
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
42/60
PrologProgramming Based on Logic
Prolog, 1972, Colmerauer
Programming logic
For Artificial Intelligence (AI) applications†
Pioneered logic programming, and remains popular
Comparatively inefficient
Example of Prolog program
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?
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
43/60
CPortable Systems Language
C, 1972, Dennis Ritchie (Bell Labs)For systems programming
Used to re-implement Unix operating systemHas also been used in many application areasEfficient code generation
Has since become the most widely usedprogramming 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
Don’t 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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
44/60
SmalltalkObject-Oriented Programming
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 iOSApps 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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
45/60
AdaLargest Design Effort in History
Ada, 1977, DoD committeeHistorical Background
More than 450 programming languagesused for DoD projectsDoD decided to develop singlehigh-level language for embedded andreal-time systemsMost extensive and expensivelanguage design effort (hundreds ofpeople, much money, about eight years)
Extremely strong typing, explicitconcurrency, 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.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
46/60
Ada (Cont.)Largest Design Effort in History
Popularity sufferedDoD no longer requires its useWidespread acceptance of C++ for OOPMost serious criticism: too large and too complex
Still widely used in both commercial and defense avionics, airtraffic 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 isbegin
return Top_Of_Stack = 0;end Is_Empty;(...omitted...)
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
47/60
C++Combining Imperative and Object-Oriented Features
C++, 1985, Bjarne Stroustrup (Bell Labs)
“The name signifies the evolutionary nature ofthe changes from C.” — StroustrupFor general-purpose programming. Goals:
Programs could be organized with classes andinheritanceLittle or no performance penalty relative to CBackward compatible to C
Large and complex, in part because it supportsboth imperative and OO programming
Rapidly grew in popularity, along with OOP
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
48/60
JavaImperative-Based Object-Oriented Language
Java, 1995, Gosling (Sun Microsystems).Based on C++
Significantly simplified (exclude struct,union, pointer arithmetic, many assignmentcoercions, some unsafe features.)Supports only OOPHas references, but not pointers
Portable; Cross-platformJava Virtual Machine conceptJIT compilers
Very popularClient-server web applicationsMost Android applications are written inJava-like language (Why Java-like?)
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
49/60
Scripting Languages
Early scripting languages were used by putting a list ofcommands, called a script, in a file to be interpreted.Now frequently used loosely to refer to dynamic high-levelgeneral-purpose languages
Dynamic languages do many tasks at runtime where staticlanguages would do them during compilationBehaviors include extension of program, by adding new code,by extending objects and definitions, or by modifying the typesystem.
Common characteristics of many scripting languages usedtoday
Support imperative, object-oriented, and functional paradigmsWhile program can be interpreted, compilers are sometimesdeveloped to improve performance of program execution
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
50/60
Scripting Languages (Cont.)
sh (for shell)
First of scripting languages
Collection of commands that were interpretedas calls to system subprograms
Perl, 1987, Larry Wall
Currently widely used as a UNIX systemadministration tool
JavaScript, 1995, Brendan Eich
Very popular as client-side HTML-embeddedscripting language
Only language that the most popular browsersshare support for
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
51/60
Scripting Languages (Cont.)
PHP, 1995, Rasmus LerdorfPHP: Hypertext Preprocessor
Recursive backronymPHP originally stood forPersonal Home Page
Very popular as server-sideHTML-embedded scriptinglanguage
Python, 1991, Guido van Rossum
General-purpose
Used by Google, YouTube, Yahoo!,CERN, NASA, . . .
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
52/60
Scripting Languages (Cont.)
Ruby, 1995, Yukihiro “Matz” MatsumotoThoroughly object-oriented
All data are objectsMost operators, like methods, can be redefined
Lua, 1993, Roberto Ierusalimschy, Luiz Henrique deFigueiredo, and Waldemar Celes:
Easily extendable
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
53/60
Objective-CCombining Imperative and Object-Oriented
Objective-C, 1983, Brad Cox and Tom Love:
C plus support for OOP based on Smalltalk
Uses Smalltalk’s method calling syntax
Used by Apple for system programming
Example of Objective-C program
# import "Process.h"
@implementation Process
- (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
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
54/60
C]Flagship .NET Language
C] (or C#), 2000, Microsoft:Pronounced as “C Sharp”
Name inspired by musical notation
Part of the Microsoft .NET development platform
Evolving rapidly
Example of C] program
using System;
class Example{
public int Number { get; set; }}
class Program{
static void Main(){
Example example = new Example();example.Number = 168;Console.WriteLine(example.Number);
}}
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
55/60
Goby Google Inc.
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 CStatic typing, garbage collection, type safety,concurrent, dynamic-typing; NO OOP
Example of Go program
package main
import "fmt"
func main() {nums := []int{2, 3, 4}sum := 0for _, num := range nums {
sum += num}fmt.Println("sum:", sum)
}
Image taken fromgolang.org.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
56/60
Swift“Objective-C without the C” — Apple Inc.
Swift, 2014, Chris Lattner and Apple Inc.:
Designed to work with Apples’ Cocoa andCocoa Touch Frameworks, and lots of existingObjective-C programs for Apple products
Meant to be more concise and resilient toerroneous code.
It was announced that Swift 2 would becomeopen 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
}
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
57/60
Miscellaneous
Document Markup LanguagesFor processing, definition, and presentation of textE.g., HyperText Markup Language (HTML), eXtensibleMarkup Language (XML), TEX, LATEX‡
Markup/Programming Hybrid LanguagesMarkup Language in which some of the elements can specifyprogramming actionsE.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 titleHello, \textbf{World}!\end{document}
‡This set of lecture notes is prepared by using LATEX.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
58/60
Programing Language Popularity
Difficult to determine popularity of programming languages
Some languages are very popular for particular kinds ofapplications
The TIOBE index (a programming language popularity index) graph from Jun-2002 toSep-2015. Available fromhttp://www.tiobe.com/index.php/content/paperinfo/tpci/index.html.
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
59/60
Table of Contents
1 Levels of Programming Languages
2 Why Programming Languages?
3 Programming Paradigms
4 Language Implementation Methods
5 Brief History of Programming Languages
6 Summary
BCS2223Programming
Paradigms
Chapter 01:Introduction
Levels ofProgrammingLanguages
WhyProgrammingLanguages?
ProgrammingParadigms
LanguageImplementationMethods
Brief History ofProgrammingLanguages
Summary
60/60
Summary
Introduced & investigated:
Levels of Programming Languages
Programming Paradigms
Language Implementation Methods
Important Programming Languages
In-depth discussion to follow in upcoming chapters.