the evolution of programming languages day 3 lecturer: xiao jia [email protected] the evolution of...
TRANSCRIPT
The Evolution of PLs 1
The Evolution of Programming Languages
Day 3Lecturer: Xiao Jia
The Evolution of PLs 3
Hoare 1968
• A fundamental feature of our understanding of the world is that we organize our experience as a number of distinct object
• We often need to construct within the computer a model of that aspect of real or conceptual world
The Evolution of PLs 4
Simula
• Simula I and Simula 67
• Purpose: to model systems• A system is a collection of interacting processes
• A process can be represented during program execution by multiple procedures each with its own Algol-style stacks
The Evolution of PLs 5
A Simula Class
class Account (real balance);begin procedure Deposit (real amount) balance := balance + amount; procedure Withdraw (real amount) balance := balance - amount;end;
The Evolution of PLs 6
Use A Simula Class
ref (Account) myAccount;MyAccount := new Account(1000);
// inherit from AccountAccount class ChequeAccount (real amount);
The Evolution of PLs 7
Features
• coroutines: simulation of concurrent processes• multiple stacks: to support coroutines• classes: combine data & collection of functions• prefixing: now as known as inheritance• garbage collection
The Evolution of PLs 8
Smalltalk
• 1969 (development) – 1972 (appear)• first implemented using BASIC• inspired by Simula and LISP
The Evolution of PLs 9
Six Principles
1. Everything is an object2. Objects communicate by sending and receiving
messages (in terms of objects)3. Objects have their own memory4. Every object is an instance of a class (which must be
an object)5. The class holds the shared behavior for its instances6. To evaluate a program list, control is passed to the first
object and the remainder is treated as its message
The Evolution of PLs 11
10 timesRepeat: [Transcript nextPutAll: ' Hi!']
message
parameter of the message
The Evolution of PLs 12
First practical Smalltalk developed in 1976 at Xerox Research Center
• an object has private data and public functions• inheritance tree with Object as its root• all classes inherit directly or indirectly from
the class Object• blocks• coroutines• garbage collection
The Evolution of PLs 13
CLU
• 1974• abstract data type (ADT)• CLU is designed for programming with ADTs
The Evolution of PLs 14
Implement a set of integersintset = cluster is create, insert, delete, member, size, choose rep = array[int] create = proc () returns (cvt) return (rep$new()) end create insert = proc (s: intset, x: int) if ~member(s, x) then rep$addh(down(s), x) end end insert member = proc (s: cvt, x: int) returns (bool) return (getind(s, x) <= rep$high(s)) end member....end intset
The Evolution of PLs 15
C++
• 1983• superset of C• hybrid language• emphasize the stack rather than the heap• multiple inheritance• NO garbage collection
The Evolution of PLs 16
Eiffel
• Software Engineering was a key objective in the design of Eiffel
• multiple inheritance• strong typing• assertions
The Evolution of PLs 17
Eiffel does not have …
• global variables• enumerations• subranges• goto, break, continue• procedure variables• casts• pointer arithmetic
• I/O defined by libraries rather than built into the language
The Evolution of PLs 18
Programming by Contract
• defensive programming
sqrt (x: real): real is require x >= 0.0 Result := .... -- square root of x ensure abs(Result * Result / x - 1.0) <= 1e-6end
The Evolution of PLs 19
Repeated Inheritanceclass House feature address: String value: Moneyendclass Residence inherit House rename value as residenceValueendclass Business inherit House rename value as businessValueendclass HomeBusiness inherit Residence Business....end
The Evolution of PLs 20
Java
• 1995• portability• security• single inheritance• interfaces• exception handling• concurrency: threads• garbage collection
The Evolution of PLs 21
Exercise
• Byte codes provide portability.• Can you suggest any other advantages of using
byte codes?
The Evolution of PLs 24
A Family
parent(pam, bob).parent(tom, bob).parent(tom, liz).parent(bob, ann).parent(bob, pat).parent(pat, jim).
Facts
The Evolution of PLs 25
Prolog Queries
?- parent(tom, liz).yes?- parent(tom, jim).no?- parent(pam, X).X = bob?- parent(bob, C).C = annC = pat?- parent(P, jim), parent(G, P).P = patG = bob
The Evolution of PLs 26
Adding Rules
grandparent(G, C) :- parent(G, P), parent(P, C).
sibling(X, Y) :- parent(P, X), parent(P, Y), different(X, Y).
?- sibling(pat, X).X = ann
The Evolution of PLs 27
Recursive Rules
ancestor(A, X) :- parent(A, X).ancestor(A, X) :- ancestor(A, P), parent(P, X).
?- ancestor(pam, jim).yes