UNIT I - Preliminary Concepts Lecture 2 - Evolution of Programming Languages
UNIT I - Preliminary Concepts Lecture 2 - Evolution of Programming Languages
Languages
1
Consider a C Language
• No dynamic variables
– All variables are global and static; no malloc(), free()
int i,j,k;
float temperature[100];
void init_temp() {
for (i=0; i<100; i++) {
temperature[i] = 0.0;
}
}
– How to program? How about hash table? binary tree?
Problems: developing scalable, large programs, making errors,
being inflexible, managing storage by programmers, … 2
Outline
• Evolution of Programming Languages (Ch. 2)
– Influences on Language Design (Sec. 1.4)
– Language Categories (Sec. 1.5)
– Programming Domains (Sec. 1.2)
3
The Dawn of Modern Computers
• Early computers (40’s and early 50’s) were
programmed using machine code directly:
– Limited hardware; no Functional programming (FP),
indexing, system software
– Computers more expensive than programmers/users
– Poor readability,
modifiability,
expressiveness
– Describe computation
flows
– Mimic von-Neumann
architecture
4
Von-Neumann Architecture
5
Early Programming
• Programmers have to enter machine code to
program the computer
– Floating point: coders had to keep track of the
exponent manually
– Relative addressing: codes had to be adjusted by
hand for the absolute addresses
– Array subscripting needed
– Something easier to remember than octal opcodes
• Early aids:
– Assembly languages and assemblers: 1-to-1
representation of machine instructions
• Saving programmer time became important …
6
Types of Languages
• Imperative Languages (Eg. FORTRAN)
• Functional Languages (Eg. LISP)
• Logical Languages (Eg. PROLOG)
• Object Oriented languages (Eg. JAVA)
7
Fortran
• First popular high-level programming language
– Computers were small and unreliable
machine efficiency was most important
– Applications were scientific
need good array handling and counting loops
• "The IBM Mathematical FORmula TRANslating
System: FORTRAN", 1954: (John Backus at IBM)
– To generate code comparable with hand-written code
using simple, primitive compilers
– Closely tied to the IBM 704 architecture, which had
index registers and floating point hardware
8
Fortran
• Fortran I (1957)
– Names could have up to six characters, formatted I/O,
user-defined subprograms, no data typing
– No separate compilation (compiling “large” programs
– a few hundred lines – approached 704 MTTF)
– Highly optimize code with static types and storage
• Later versions evolved with more features and
platform independence
– Almost all designers learned from Fortran and Fortran
team pioneered things such as scanning, parsing,
register allocation, code generation, optimization
9
Program Compilation
Process
10
FORTRAN and von-Neumann Arch.
• FORTRAN, and all other imperative languages,
which dominate programming, mimic von-
Neumann architecture
– Variables memory cells
– Assignment statements data piping between
memory and CPU
– Operations and expressions CPU executions
– Explicit control of execution flows
– Efficient mapping between language and HW
efficient execution performance, but limited by
von Neumann bottleneck
11
Von-Neumann bottleneck
• The term is named for John von Neumann, who
developed the theory behind the architecture of
modern computers.
• Earlier computers were fed programs and data for
processing while they were running.
• The von Neumann bottleneck is a limitation on
throughput caused by the standard personal computer
architecture.
• An instruction fetch and a data operation cannot occur
at the same time because they share a common bus.
12
Pipeline in
Computing
13
FORTRAN Programming Style
• Global view, top down i=0; f=0;
• Program starts from first
executable statement and N
follow a sequential flow i<N
with go-to Y
– Conceptually, a large f = f + c[i]*x[i]; f = 0;
main() including
everything but without
main() declaration, i = i+1;
though FORTRAN has functions
– Match a flow chart with traces
15
Fortran – Factorial of a number
18
Functional Programming: LISP
• AI research needed a language to
– Process data in lists (rather than arrays)
– Symbolic computation (rather than numeric)
• John McCarthy of MIT developed LISP (LISt
Processing language) in 1958
• A LISP program is a list:
(+ a (* b c))
– List form both for input and for function
– Only two data types: atoms and lists
19
LISP
• Example: a factorial function in LISP
(defun fact (x)
(if (<= x 0)
1
(* x (fact (- x 1)))
)
)
• Second-oldest general-purpose programming
language still in use
– Ideas, e.g. conditional expression, recursion, garbage
collection, were adopted by other imperative languages.
20
Example: LISP code
21
LISP code – Computing x y
(defun power (x y)
(if (> y 0)
(* x
(power x (- y 1)))
1))
(power 2 3)
22
LISP Code – Add list
23
LISP – Exercises – Assignment 1
Submission Deadline: 2nd Aug, 2017
• Write a function that can add two list to one, such
as (add '(1 2 3) '(4 5 6)) = (5 7 9) (1 2 3)
(2 3 4)
• Write a function to add multiple list (3 4 5)
(8 7 6)
(14 16 18)
• To calculate the average of a list such as
((1 1 1)
(2 2 2)
(3 3 3))
= (2 2 2)
25
First Step Towards Sophistication
• Environment (1957-1958):
– FORTRAN had (barely) arrived for IBM 70x
– Many other languages, but all for specific machines no
universal language for communicating algorithms
– Programmer productivity became important
• ALGOL: Universal, international, machine-independent
(imperative) language for expressing scientific
algorithms
– ALGOL ALGOrithm Logic
– Eventually, 3 major designs: ALGOL 58, 60, and 68
– Developed by increasingly large international committees
26
Issues to Address (I)
• Early languages used label-oriented control:
27 ……
… GO TO 27
30 IF (A-B) 5,6,7
28
Example of Orthogonality
Storing in a variable ✓ ✓ ✓
Storing in an array ✓ ✓ ✓
30
Backus-Naur Form (BNF)
31
COBOL - 1960
• COmmon Business Oriented Language
• First macro facility in a high-level language
• Hierarchical data structures (records)
• Nested selection statements
• Long names (up to 30 characters), with
hyphens
32
Beginning of Timesharing: BASIC
• BASIC (Beginner’s All-purpose Symbolic Instruction
Code)
– John Kemeney and Thomas Kurtz at Dartmouth, 1963
• Design goals:
– Easy to learn and use for non-science students
– Must be “pleasant and friendly”
– Fast turnaround for homework
– Free and private access
– User time is more important than computer time
• First widely used language with time sharing
– Simultaneous individual access through terminals
33
Everything for Everybody PL/1
• Programming Language One
• IBM at 1963-1964:
– Scientific computing: IBM 1620 and 7090, FORTRAN
– Business computing: IBM 1401 and 7080, COBOL
– Scientific users began to need elaborate I/O, like in COBOL;
business users began to need FP and arrays
• The obvious solution
– New computer to do both IBM System/360
– Design a new language to do both PL/I
• Results:
– Unit-level concurrency, first exception handling, pointer
– But, too many and too complex features
34
SNOBOL (1964)
• SNOBOL “Snow Ball” StriNg Oriented and
symBOlic Language
• Designed as a string manipulation language
• Designed specifically for text processing.
• Designed at Bell Labs by Farber, Griswold, and
Polensky
• Powerful operators for string pattern matching
• Application: writing text editors
35
Beginning of Data Abstraction
• SIMULA (between 1962 and 1964)
– Designed primarily for System Simulation in University
of Oslo, Norway, by Kristen Nygaard and Ole-Johan Dahl
• Starting 1961: SIMULA I, SIMULA 67
• Primary contributions:
– Co-routines: a kind of subprogram
– Implemented in a structure called a class, which include
both local data and functionality and are the basis for
data abstraction
36
C (1972)
• Designed for systems programming
• Designed at Bell Labs by Dennis Richie
• Evolved primarily from B, but also ALGOL 68
• Powerful set of operators, but poor type
checking
• Initially spread through UNIX
37
Example Program in C
#include<stdio.h>
int main()
{
int balance = 100;
float f = 'a';
printf("%f \n", balance+f);
return 0;
}
38
Object-Oriented Programming
• Smalltalk (1972)
• Initially designed by Alan Kay, later by Adele Goldberg at
Xerox PARC
• First full implementation of an object-oriented language
– Everything is an object: variables, constants, activation
records, classes, etc.
– All computation is performed by objects sending and
receiving messages
– Data abstraction, inheritance, dynamic type binding
• Also pioneered graphical user interface design
39
C++ (1985)
• Developed at Bell Labs by Stroustrup
• Evolved from C and SIMULA 67
• Facilities for object-oriented programming, taken
partially from SIMULA 67, were added to C
• Also has exception handling
• A large and complex language in part, because it
supports both procedural and OO programming
• Rapidly grew in popularity, along with OOP
• ANSI standard approved in November, 1997
40
Java (1995)
• Developed at Sun in the early 1990s
• Based on C++
• Significantly simplified
• Supports only OOP
• Has references, but not pointers
• Includes support for applets and a form of
concurrency
41
Programming Based on Logic:
Prolog
• Developed by Comerauer and Roussel (University of Aix-
Marseille) in 1972, with help from Kowalski (University of
Edinburgh)
• Based on formal logic
• Non-procedural
– Only supply relevant facts (predicate calculus) and inference rules
(resolutions)
– System then infer the truth of given queries/goals
• Can be summarized as being an intelligent database
system that uses an inferencing process to infer the truth
of given queries
42
Logic Languages
• Example: relationship among people
How do you add the following facts?
44
Here are the resultant clauses:
-------------------------------
male(james1).
male(charles1).
male(charles2).
male(james2).
male(george1).
female(catherine).
female(elizabeth).
female(sophia).
Here is how you would formulate the following
parent(charles1, james1). queries:
parent(elizabeth, james1).
parent(charles2, charles1). Was George I the parent of Charles I?
parent(catherine, charles1). Query: parent(charles1, george1).
parent(james2, charles1). Who was Charles I's parent?
parent(sophia, elizabeth). Query: parent(charles1,X).
parent(george1, sophia). Who were the children of Charles I?
Query: parent(X,charles1).
46
Summary: Application Domain
• Application domains have distinctive (and conflicting)
needs and affect prog. lang.
– Scientific applications: high performance with a large number of
floating point computations, e.g., Fortran
– Business applications: report generation that use decimal
numbers and characters, e.g., COBOL
– Artificial intelligence: symbols rather than numbers manipulated,
e.g., LISP
– Systems programming: low-level access and efficiency for SW
interface to devices, e.g., C
– Web software: diff. kinds of lang. markup (XHTML), scripting
(PHP), general-purpose (Java)
Summary: Programming
Methodology in Perspective
• 1950s and early 1960s: simple applications; worry
about machine efficiency (FORTRAN)
• Late 1960s: people efficiency important; readability,
better control structures (ALGOL)
– Structured programming
– Top-down design and step-wise refinement
• Late 1970s: process-oriented to data-oriented
– Data abstraction
• Middle 1980s: object-oriented programming
– Data abstraction + inheritance + dynamic binding
48
Theory of PL: Turing Equivalence
• Languages have different strengths, but fundamentally
they all have the same power
{problems solvable in Java}
= {problems solvable in Fortran}
=…
• And all have the same power as various mathematical
models of computation
= {problems solvable by Turing machine}
= {problems solvable by lambda calculus}
=…
• Church-Turing thesis: this is what “computability” means
49
Turing Test in Computers
• The Turing test, developed by Alan Turing in 1950
– It is a test of a machine's ability to exhibit intelligent
behavior equivalent to, or indistinguishable from, that
of a human.
• Lambda calculus (also written as λ-calculus)
– It is a formal system in mathematical logic for
expressing computation based on function abstraction
and application using variable binding and
substitution.
50