CS ExCo Advanced in Topics Object-Oriented Programming.
-
Upload
brian-poole -
Category
Documents
-
view
229 -
download
5
Transcript of CS ExCo Advanced in Topics Object-Oriented Programming.
CS ExCo
Advanced in TopicsObject-Oriented Programming.
Connections Between:Functional & OO
Section 1:Language
History
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
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
A Bit of ProgrammingLanguages HistoryTaken From:
Gelernter, David Hillel Programming Linguistics MIT Press, 1990
But first…
What is a “Hero” language?
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
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?
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
Algol 60: Hero?
Discovered Recursive Program Structure.
Yes
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
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
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
“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.
Simula 67
The first Object-Oriented Language!
The “Algol Wall” falls at last!The “Algol Wall” falls at last! Well, almost
Simula 67: the languageProgram StructureRecursiveSame as others
Data StructureRecursiveDynamicClasses & Objects Classes instantiate
objects Classes have code
and take parameters
Inheritance
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);
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]
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
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
JavaAnonymous Inner ClassesGJ will have pretty good generics semanticsSimplifies C++ greatly
Our Hero
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
BETAEverything is a “pattern”Patterns make up classes and methodsThere is no direct representation of an objectVery similar to functional languages like SchemeStrongly typed
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