310 likes | 435 Views
The Evolution of Programming Languages. Day 3 Lecturer: Xiao Jia xjia@cs.sjtu.edu.cn. The Object Oriented Paradigm. Hoare 1968. A fundamental feature of our understanding of the world is that we organize our experience as a number of distinct object
E N D
The Evolution of Programming Languages Day 3 Lecturer: Xiao Jia xjia@cs.sjtu.edu.cn The Evolution of PLs
The Object Oriented Paradigm The Evolution of PLs
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
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
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
Use A Simula Class ref (Account) myAccount; MyAccount := new Account(1000); // inherit from Account Account class ChequeAccount (real amount); The Evolution of PLs
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
Smalltalk • 1969 (development) – 1972 (appear) • first implemented using BASIC • inspired by Simula and LISP The Evolution of PLs
Six Principles • Everything is an object • Objects communicate by sending and receiving messages (in terms of objects) • Objects have their own memory • Every object is an instance of a class (which must be an object) • The class holds the shared behavior for its instances • To evaluate a program list, control is passed to the first object and the remainder is treated as its message The Evolution of PLs
10 timesRepeat: [Transcript nextPutAll: ' Hi!'] receiver The Evolution of PLs
10 timesRepeat: [Transcript nextPutAll: ' Hi!'] message parameter of the message The Evolution of PLs
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
CLU • 1974 • abstract data type (ADT) • CLU is designed for programming with ADTs The Evolution of PLs
Implement a set of integers intset = 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
C++ • 1983 • superset of C • hybrid language • emphasize the stack rather than the heap • multiple inheritance • NO garbage collection The Evolution of PLs
Eiffel • Software Engineering was a key objective in the design of Eiffel • multiple inheritance • strong typing • assertions The Evolution of PLs
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
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-6 end The Evolution of PLs
Repeated Inheritance class House feature address: String value: Money end class Residence inherit House rename value as residenceValue end class Business inherit House rename value as businessValue end class HomeBusiness inherit Residence Business .... end The Evolution of PLs
Java • 1995 • portability • security • single inheritance • interfaces • exception handling • concurrency: threads • garbage collection The Evolution of PLs
Exercise • Byte codes provide portability. • Can you suggest any other advantages of using byte codes? The Evolution of PLs
Homework • Kevo • Beta • Blue • CLOS • Self • Io The Evolution of PLs
Backtracking Languages (we only talk about Prolog[1972]) The Evolution of PLs
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
Prolog Queries ?- parent(tom, liz). yes ?- parent(tom, jim). no ?- parent(pam, X). X = bob ?- parent(bob, C). C = ann C = pat ?- parent(P, jim), parent(G, P). P = pat G = bob The Evolution of PLs
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
Recursive Rules ancestor(A, X) :- parent(A, X). ancestor(A, X) :- ancestor(A, P), parent(P, X). ?- ancestor(pam, jim). yes The Evolution of PLs
Cut minimum(X, Y, X) :- X <= Y. minimum(X, Y, Y) :- X > Y. The Evolution of PLs
Cut minimum(X, Y, X) :- X <= Y, !. minimum(X, Y, Y) :- X > Y, !. The Evolution of PLs
Cut different(X, X) :- !, fail. different(X, Y). ?- different(Tom, Tom). no ?- different(Ann, Tom). yes The Evolution of PLs