CS ExCo Advanced in Topics Object-Oriented Programming.

23
CS ExCo Advanced in Topics Object-Oriented Programming.

Transcript of CS ExCo Advanced in Topics Object-Oriented Programming.

Page 1: CS ExCo Advanced in Topics Object-Oriented Programming.

CS ExCo

Advanced in TopicsObject-Oriented Programming.

Page 2: CS ExCo Advanced in Topics Object-Oriented Programming.

Connections Between:Functional & OO

Section 1:Language

History

Page 3: CS ExCo Advanced in Topics Object-Oriented Programming.

Why Do We Care?

-Calculus

Functional Programming•Impractical•Strong Mathematical

Properties

Procedural•Practical•Little Math Grounding

Object-Oriented•Very Practical

(fixes problems)•No Math Basis/

Chaos Theory

Turing Machine

Page 4: CS ExCo Advanced in Topics Object-Oriented Programming.

What We Want to See:Functional Programming

•Impractical•Strong Mathematical

Properties

Object-Oriented•Very Practical

(fixes problems)•No Math Basis/

Chaos Theory

Future OOVery practical

Many Nice Mathematical properties

Page 5: CS ExCo Advanced in Topics Object-Oriented Programming.

A Bit of ProgrammingLanguages HistoryTaken From:

Gelernter, David Hillel Programming Linguistics MIT Press, 1990

But first…

What is a “Hero” language?

Page 6: CS ExCo Advanced in Topics Object-Oriented Programming.

Fortran (1957-66)Program StructureFlat No recursion No nested scopes

No statement grouping No control structures

goto & computed goto if (like computed goto) do (based around

labels)

Static

Data StructureFlat Arrays Later strings Only locals & globals

Static No dynamic

allocation All locations picked

at compile time

Page 7: CS ExCo Advanced in Topics Object-Oriented Programming.

Hero!Achieved its goal to replace assembly

Got people to actually use programming languages

Fortran:Abstractions? Hero?

Functions/ProceduresAbsolutely no layered abstraction Layered Abstraction: “first understand

in general or in the abstract what’s going on; then worry about the details.” Apply recursively for best effect

At Least its consistent

Hero? Or Villain?

Page 8: CS ExCo Advanced in Topics Object-Oriented Programming.

Algol 60Program Structure

Recursive Nested scopes Modules Recursive function calls Full set of control

structures

Static

Data StructureFlat Arrays No records

Dynamic Dynamically sized

arrays

“Algol Wall”Data and program structure

Are separate worlds

Page 9: CS ExCo Advanced in Topics Object-Oriented Programming.

Algol 60: Hero?

Discovered Recursive Program Structure.

Yes

Page 10: CS ExCo Advanced in Topics Object-Oriented Programming.

Lisp (60-65)Program StructureRecursive Structure Calls

Static Functions still aren’t

first class values

Dynamic Binding variables are bound

within the calling environment

Data StructureRecursive Atoms Lists

Heterogeneous ListsDynamic Garbage collection

No records

Page 11: CS ExCo Advanced in Topics Object-Oriented Programming.

COBOL (1960-61)

Program StructureFlat Back to this again No parameter

accepting subroutines

No nested scopes

Static

Data StructureRecords FINALLY! Tied to files Not “templates”

for records

Static No dynamic

allocation

A step back, IMHO

Page 12: CS ExCo Advanced in Topics Object-Oriented Programming.

PL/I (1964) and Algol 68

PL/I for example: DECLARE FOOBAR DECIMAL FIXED REAL (8,3)

STATIC EXTERNAL

Algol 68: Allows anything, for example:this is an acceptable name for a variable of type integer

Operator overloading, unions, pointers to anything, Call-by-reference

Everything is first class and transparent, including procedures

Yet: procedures are objects while structs “extend the language”, structures are based on arrays and one has data and programs and never shall the twain meet

COMPLEX

Page 13: CS ExCo Advanced in Topics Object-Oriented Programming.

“In an array structure, all components are of the same type…. In a record, the components (called fields) are not necessarily of he same type”

-Wirth

Pascal (1971-74)Program StructurePartially recursive Procedures with

recursive calls No true blocks, only

compound statements

Static

Data StructureFlatRecords Dynamic Record types extend

type system Based on arrays

Strongly typed

Most importantly its simple!This temporarily reversed the trend.

Page 14: CS ExCo Advanced in Topics Object-Oriented Programming.

Simula 67

The first Object-Oriented Language!

The “Algol Wall” falls at last!The “Algol Wall” falls at last! Well, almost

Page 15: CS ExCo Advanced in Topics Object-Oriented Programming.

Simula 67: the languageProgram StructureRecursiveSame as others

Data StructureRecursiveDynamicClasses & Objects Classes instantiate

objects Classes have code

and take parameters

Inheritance

Page 16: CS ExCo Advanced in Topics Object-Oriented Programming.

Fateful ChoicesBroke down the “Algol Wall” by making data like proceduresWe loose a way to describes object instances, just as there is no way to describe procedure instancesClasses andprocedures arethe same butdistinguishedby syntax asdifferent

class ACCOUNT(balance); real balance;begin integer acctNum;

accrNum := getNextAcctNum();procedure DEPOSIT(amount);

real amount;balance := balance +

amount;end

…ref (ACCOUNT) MyAcct;MyAcct :- new ACCOUNT(45);

Page 17: CS ExCo Advanced in Topics Object-Oriented Programming.

Smalltalk (1972-76)No primitivesClasses are objectsEven blocks are objectsDynamically typedExtremely uniformDespite all this, it never was quite “it”

Syntax is nearly unreadable, example: Given a “Point” class the plus method might be:

+pt [ Point new x: x+pt x y: y+pt y]

Page 18: CS ExCo Advanced in Topics Object-Oriented Programming.

Ada (mid 1970s)A complicated language designed for the DODBased on PascalMany different forms of packaging and data type declarationsStrong typing with the flexibility of making new typesSecurity was important (unlike Smalltalk and Scheme)No quite Object-Oriented

Page 19: CS ExCo Advanced in Topics Object-Oriented Programming.

C, C++ and EiffelC gave us { } for blocks and lots of other nice syntaxC++ made OO and exceptions mainstreamConst allows expression of invarianceEiffel is in the Pascal familyIt is a well thought out OO languageGave us the concept of whole program optimizationHopefully the last of the Pascal line

Page 20: CS ExCo Advanced in Topics Object-Oriented Programming.

JavaAnonymous Inner ClassesGJ will have pretty good generics semanticsSimplifies C++ greatly

Our Hero

Page 21: CS ExCo Advanced in Topics Object-Oriented Programming.

Prototype Based OO LanguagesSelf etc.

No classes, only objectsNew objects are made by cloning othersA “class” is just an object you use as a templateCan directly write objects and often add methods/properties on the flyMay be strongly or weakly typed

Page 22: CS ExCo Advanced in Topics Object-Oriented Programming.

BETAEverything is a “pattern”Patterns make up classes and methodsThere is no direct representation of an objectVery similar to functional languages like SchemeStrongly typed

Page 23: CS ExCo Advanced in Topics Object-Oriented Programming.

The Future?Patterns are first class entities representing classes and methodsDirect object representations allow inner objects and modulesWays to express invarianceAnonymous patterns and objectsIntegration of Generics into the polymorphism system