58
OO History: Simula and Smalltalk 17-396: Language Design and Prototyping Jonathan Aldrich Spring 2020

OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

OO History: Simula and Smalltalk

17-396: Language Design and Prototyping

Jonathan Aldrich

Spring 2020

Page 2: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Learning Goals

• Know the motivation for, precursors of, and history of objects

• Understand the design of a pure object-oriented language

• Understand the key benefits of objects that drove adoption

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich2

Page 3: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Outline

• The beginnings of objects– Simulation in Simula 67

– Demonstration: the first OO language

• Pure OO in Smalltalk– Historical context and goals

– Demonstration: a pure object model

• The benefits and adoption of objects

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich3

Page 4: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Simulation at the NCC in 1961

• Context: Operations research– Goal: to improve decision-

making by simulating complexsystems

• Discrete-event simulationsin domains like traffic analysis

– Kristin Nygaard and Ole-JohanDahl at the NorwegianComputing Center

• Development of SIMULA I– Goal: SIMULA "should be problem-oriented and not computer-oriented, even if

this implies an appreciable increase in the amount of work which has to be done by the computer.“

– Modeled simulations “as a variable collection of interacting processes"– Design approach: "Instead of deriving language constructs from discussions of the

described systems combined with implementation considerations, we developed model system properties suitable for portraying discrete event systems, considered the implementation possibilities, and then settled the language constructs."

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich4

Page 5: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

SIMULA: a Motivating Problem

• Need to store vehicles in a toll booth queue.

• Want to store vehicles in a linked list to represent the queue

• Each vehicle is either a car, a truck, or a bus.

• Different kinds of vehicles interact with the toll booth in different ways

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich5

Page 6: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Needs Motivating OOP

• Issues with SIMULA I

– Since each object in a simulation was a process, it was awkward to get attributes of other objects

– "We had seen many useful applications of the process concept to represent collections of variables and procedures, which functioned as natural units of programming” motivating more direct support for this

– "When writing simulation programs we had observed that processes often shared a number of common properties, both in data attributes and actions, but were structurally different in other respects so that they had to be described by separate declarations.”

– “memory space [was] our most serious bottleneck for large scale simulation.”

[source: Kristen Nygaard and Ole-Johan Dahl, The Development of the SIMULA Languages, History of Programming Languages Conference, 1978]

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich6

Page 7: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Needs Motivating OOP

• Issues with SIMULA I

– Since each object in a simulation was a process, it was awkward to get attributes of other objects

– "We had seen many useful applications of the process concept to represent collections of variables and procedures, which functioned as natural units of programming” motivating more direct support for this

– "When writing simulation programs we had observed that processes often shared a number of common properties, both in data attributes and actions, but were structurally different in other respects so that they had to be described by separate declarations.”

– “memory space [was] our most serious bottleneck for large scale simulation.”

[source: Kristen Nygaard and Ole-Johan Dahl, The Development of the SIMULA Languages, History of Programming Languages Conference, 1978]

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich7

Garbage collection was a good technology for the memory problem. The others required new ideas.

Page 8: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Hoare’s Record Classes

• C. A. R. Hoare proposed Record Classes in 1966– Goal: capture similarity and variation in data structures

– Earliest inheritance-like construct

record class Expression (

subclasses

Constant(real value),

Variable(string name),

BinaryExpr(reference(Expression) left, right;

subclasses Sum, Difference, Product, Quotient));

• Each class described a particular record structure

• A subclass shared fields from its parent

• Variables could take any type in the subclass hierarchy

• A record class discriminator provided case analysis on the record type

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich8

Expression

Constantvalue: real

Variablename: string

BinaryExprleft: reference(Expression)right: reference(Expression)

Sum

Product Quotient

Difference

Page 9: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Hoare’s Record Classes

• C. A. R. Hoare proposed Record Classes in 1966– Goal: capture similarity and variation in data structures

– Earliest inheritance-like construct

record class Expression (

subclasses

Constant(real value),

Variable(string name),

BinaryExpr(reference(Expression) left, right;

subclasses Sum, Difference, Product, Quotient));

• Each class described a particular record structure

• A subclass shared fields from its parent

• Variables could take any type in the subclass hierarchy

• A record class discriminator provided case analysis on the record type

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich9

Expression

Constantvalue: real

Variablename: string

BinaryExprleft: reference(Expression)right: reference(Expression)

Sum

Product Quotient

Difference

Dahl and Nygaard’s observations on record classes:• "We needed subclasses of processes with...actions...not only of pure

data records"• "We also needed to group together common process properties in such

a way that they could be applied later, in a variety of different situations not necessarily known in advance"

Page 10: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

SIMULA 67’s Class Prefix Idea

• Create a Link class to represent the linked list• Add the Link class as a prefix to vehicles, which are subclasses

– Today we would say this is not a good design—but it nevertheless was enough to motivate a good idea

• As in Hoare’s design, subclassing is hierarchical– Car, Truck, etc. are subclasses of Vehicle

• Unlike Hoare’s classes, Simula classes can have virtual procedures– Allows subclasses to override behavior for the toll booth

• Unlike in Hoare’s design, each class was declared separately– Link could be reused for other linked lists, not just lists of vehicles– Supports extensibility: can add RVs later as a subclass of Vehicle

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich10

Page 11: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Hello World in Simula (Demo)begin

OutText("Hello, world!");

OutImage

end

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich11

writes text to the current image (line) being created

writes the current image to standard output

Page 12: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Simulating Vehicles (Demo)begin

class Vehicle;virtual: procedure sound is procedure sound;;

beginend;

Vehicle class Car;begin

procedure sound;begin

OutText("Beep beep!");OutImage;

end;end;

Vehicle class Bike;begin

procedure sound;begin

OutText("Ding ding!");OutImage;

end;end;

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich12

ref (Vehicle) array vehicles (1 : 2);

Integer i;

vehicles (1) :- new Car;

vehicles (2) :- new Bike;

for i := 1 step 1 until 2 do

vehicles(i).sound

end;

virtual methods can be overridden in subclasses

(equiv. of non-final in Java)

overriding the sound method in a subclass

A size 2 array of references to

Vehicles

Car and Bike are subtypes of Vehicle

Dispatches to code in the car and bike

Page 13: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Co-routines (Demo)begin

ref (Car) aCar;

ref (Truck) aTruck;

class Car;

begin

Integer N;

detach;

for N := 1 step 1 until 10 do

begin

OutText("Driving me insane!");

OutImage;

resume(aTruck);

end;

end;

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich13

class Truck;

begin

Integer N;

detach;

for N := 1 step 1 until 10 do

begin

OutText("Keep on truckin'!");

OutImage;

resume(aCar);

end;

end;

aCar :- new Car;

aTruck :- new Truck;

resume(aCar);

end;

each class has code that runs when objects are created

we immediately suspend execution until set up is done

let the truck take a step in the simulation start the simulation

with the car

create the car and truck

continue the car simulation

Page 14: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk Context: Personal Computing

• The Dynabook at Xerox PARC:“A Personal Computer forChildren of All Ages”

• Funded by US Govt (ARPA, the folks who brought you the internet) to facilitate portable maintenance documentation

• Alan Kay’s goal– Amplify human reach

– Bring new ways of thinking to civilization(Still a goal of CS research – e.g. see computational thinking work at CMU)

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich14

Alan Kay with a Dynabookprototype

Page 15: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk and Simula

“What I got from Simula was that you could now replace bindings and assignment with goals. The last thing you wanted any programmer to do is mess with internal state even if presented figuratively. Instead, the objects should be presented as sites of higher level behaviors more appropriate for use as dynamic components.”

- Alan Kay, The early history of Smalltalk. In History ofprogramming languages—II, 1993.

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich15

Page 16: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk

• The name– “Children should program in…”

– “Programming should be a matter of…”

• Pure OO language– Everything is an object (including true, “hello”, and 17)

– All computation is done via sending messages• 3 + 4 sends the “+” message to 3, with 4 as an argument

• To create a Point, send the “new” message to the Point class– Naturally, classes are objects too!

• Garbage collected– Following Lisp and Simula 67

• Reflective– Smalltalk is implemented (mostly) in Smalltalk

• A few primitives in C or assembler

– Classes, methods, objects, stack frames, etc. are all objects• You can look at them in the debugger, which (naturally) is itself implemented in Smalltalk

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich16

Page 17: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk Demo

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich17

Page 18: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

The Double Dispatch Pattern

• Problem: behavior depends on two different classes

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich18

Integer Fraction Float Complex

Integer Integer Fraction Float Complex

Fraction Fraction Fraction Float Complex

Float Float Float Float Complex

Complex Complex Complex Complex Complex

Right Operand

LeftOperand

Result Type for Addition Operation

Page 19: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

The Double Dispatch Pattern

• Problem: behavior depends on two different classes

• Solution: dispatch twice

class Fraction

method + aNumber

| n d d1 d2 |

aNumber isFraction ifTrue:

[d := denominator gcd: aNumber denominator…].

^ aNumber adaptToFraction: self andSend: #+

class Integer

method adaptToFraction: rcvr andSend: selector

^ rcvr perform: selector with: (Fraction numerator: self denominator: 1)

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich19

First dispatch to Fraction’s + method:if both numbers are fractions, we

compute the greatest common denominator (GCD) and proceed…

otherwise we ask the other number to turn itself into a

fraction, and then add self to it

Second dispatch to Integer’s adaptToFraction:andSend methodInteger does so by creating a fraction with itself as the

numerator and a denominator of 1. perform is a reflective method that calls ‘+’ (the selector) in this case

Page 20: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

The Double Dispatch Pattern

• Problem: behavior depends on two different classes

• Solution: dispatch twice

class Fraction

method + aNumber

| n d d1 d2 |

aNumber isFraction ifTrue:

[d := denominator gcd: aNumber denominator…].

^ aNumber adaptToFraction: self andSend: #+

class Float

method adaptToFraction: rcvr andSend: selector

^ rcvr asFloat perform: selector with: self

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich20

if both numbers are fractions, we compute the greatest common

denominator (GCD) and proceed…

otherwise we ask the other number to turn itself into a

fraction, and then add self to it

On the other hand, Float says “no, actually a fraction should adapt to me before addition.”

Page 21: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk: Classes as Factories

“Creating different kinds of collections with a factory method”

OrderedCollection newFrom: #(3 2 2 1).

SortedCollection newFrom: #(3 2 2 1).

Set newFrom: #(3 2 2 1).

“Classes – and thus the factories – are first-class. We can assign them to a factory object and then use it to create different kinds of collections.”

factoryObj := Set.

factoryObj newFrom: #(3 2 2 1).

factoryObj := OrderedCollection.

factoryObj newFrom: #(3 2 2 1).

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich21

Page 22: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Smalltalk, according to Alan Kay

• “In computer terms, Smalltalk is a recursion on the notion of computer itself. Instead of dividing “computer stuff” into things each less strong than the whole—like data structures, procedures, and functions which are the usual paraphernalia of programming languages—each Smalltalk object is a recursion of the entire possibilities of the computer.

• “…everything we describe can be represented by the recursive composition of a single kind of behavioral building block that hides its combination of state and process inside itself and can be dealt with only through the exchange of messages.

• “Thus [Smalltalk’s] semantics are a bit like having thousands and thousands of computers all hooked together in a very fast network.”

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich22

Page 23: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Dan Ingalls’ perspective

• Computing should be viewed as an intrinsic capability of objects that can be uniformly invoked by sending messages... Instead of a bit-grinding processor raping and plundering data structures, we have a universe of well-behaved objects that courteously ask each other to carry out their various desires.– Daniel Ingalls, Design Principles Behind Smalltalk (1981)

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich23

Page 24: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Impact of Smalltalk and Simula

• Mac (and later Windows): inspired by Smalltalk GUI

• GUI frameworks– Smalltalk MVC MacApp Cocoa, MFC, AWT/Swing, …

• C++: inspired by Simula 67 concepts

• Objective C: borrows Smalltalk concepts, syntax

• Java: garbage collection, bytecode from Smalltalk

• Ruby: pure OO model almost identical to Smalltalk– All dynamic OO languages draw from Smalltalk to some extent

• Design and process ideas impacted by Smalltalk– Patterns, Refactoring, Extreme programming/Agile movement

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich24

Page 25: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Why has OOP been successful?

• Think and share your ideas

25

Material from “The Power of Interoperability: Why Objects Are Inevitable”by Jonathan Aldrich, Onward! Essay, 2013.

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 26: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Why has OOP been successful?

“the object-oriented paradigm...isconsistent with the natural way ofhuman thinking”

- [Schwill, 1994]

OOP may have psychological benefits.

But is there a technical characteristic ofOOP that is critical for modern software?

26OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 27: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

What Makes OOP Unique?

Candidates: key features of OOP

• Encapsulation?– Abstract data types (ADTs) also provide

encapsulation

• Inheritance?

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich27

Page 28: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Not all OO Languages Have Inheritance

• A Modern Example: Go– Provides encapsulation, interfaces, dynamic dispatch

– But no inheritance of code from a superclass

• An Alternative: Delegation– Supported in Self, JavaScript, others

– There are no classes, only objects. To get a new object:

• Create an empty object

– Add things to it

– Optionally, delegate to an existing object via a parent field

» If you call method m on an object, and m is not defined, the system will look for it in the parent object

• Clone an existing object

28OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 29: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Inheritance vs. Delegation, Graphically

Source: Ungar and Smith. Self: The Power of Simplicity. Lisp and Symbolic Computation, 1991.

29

The Self project also had a big impact on optimization of dynamic compilers• E.g. [Chambers & Ungar, 1989]• Used in Java, JavaScript, etc.

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 30: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Inheritance has Benefits, Drawbacks

• Benefits– No easier way to reuse a partial implementation of an abstraction

– Alternative requires forwarding each method individually

– Especially useful when subclass and superclass call each other

• E.g. a class with both super calls and a template method

• Implementing Template Method, Factory is awkward in Go[Schmager, Cameron, and Noble 2010]

• Drawbacks– Tight coupling between subclass and superclass

• E.g. fragile base class problem

– Drawbacks mitigated by careful methodology

30OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 31: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Fragile Base Class Problemclass List {

private Link head;public void add(int i) {…}public void addAll(List l) {…}public int size() {

… // traverses the list}

}

class CachedSizeList extends List {private int cachedSize;public int size() { return cachedSize; }public void add(int i) {

cachedSize++;super.add(i);

}// do we need to override addAll?

}

• Correct impl of subclass depends on the base class implementation

– Couples classes, breaks modularity

• Worse: if the base class changes, the subclass will be broken

• What causes this coupling is also what enables reuse through inheritance!

– Example: addAll() reuses the implementation of add()

• This is called the Template Method pattern

• Some solutions– Document internal method calls that

can be intercepted• Document whether addAll() calls add()

– Only make self-calls to abstract or final methods

– Selective open recursion – language feature describes which methods are used for downcalls [Aldrich and Donnelly, 2004]

31OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 32: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

What Makes OOP Unique?

Candidates: key features of OOP

• Encapsulation?– Abstract data types (ADTs) also provide

encapsulation

• Inheritance?– Neither universal nor unique in OOPLs

– Worth studying, but not our focus

• Polymorphism/Dynamic dispatch?– Every OOPL has dynamic dispatch

– Distinguishes objects from ADTs

animal.speak()

“meow”“woof”

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich32

Page 33: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Dynamic Dispatch as Central to OOP

Significant grounding in the OO literature

• Cook’s 2009 Onward! essay– Object: “value exporting a procedural interface to data or behavior”

– Objects are self-knowing (autognostic), carrying their own behavior

– Equivalent to Reynolds’ [1975] procedural data structures

• Historical language designs– “the big idea [of Smalltalk] is messaging” [Kay, 1998 email]

• Design guidance– “favor object composition over class inheritance” [Gamma et al. ’94]

– “black-box relationships [based on dispatch, not inheritance] are an ideal towards which a system should evolve” [Johnson & Foote, 1988]

33OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 34: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Objects vs. ADTs

Two Object-Oriented Setsinterface IntSet {

bool contains(int element)bool isSubsetOf(IntSet otherSet)

}

class IntSet1 implements IntSet {…}class IntSet2 implements IntSet {…}

// in main()IntSet s1 = new IntSet1(...);IntSet s2 = new IntSet2(...);bool x = s1.isSubsetOf(s2);

34

Set Objects

Different implementations interoperate freely

{1} {1,2} = true

{1} {1,2} = true

{1} {1,2} = true

Interface is a set of messages

All communication is message-based; isSubsetOf() implemented by calling contains() on otherSet

Page 35: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Objects vs. ADTsTwo Set ADTsfinal class IntSetA {

bool contains(int element) { ... }

bool isSubsetOf(IntSetA other) { ... }

}

final class IntSetB {

bool contains(int element) { ... }

bool isSubsetOf(IntSetB other) { ... }

}

// in main()

IntSet sA = new IntSetA(...);

IntSet sB = new IntSetB(...);

bool x = sA.isSubsetOf(sB); // ERROR!

35

Set ADTs

Different ADT implementations cannot interoperate

{1} {1,2} = true

{1} {1,2} = true

Interface is a set of operations over a fixed but hidden type (IntSetA)

isSubsetOf() is a binary method that only works with other instances of IntSetA. Good for performance.

{1} {1,2}X

Page 36: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

ADT Performance Up Close

• Assume Set ADT uses sorted array• isSubsetOf can be O(n)

– Single linear scan through both arrays– Find each element of first array in second– Because both are sorted, never backtrack in second array

• OO implementation cannot use this trick– The other object may not be implemented based on an array

• Unless we do an instanceof test – but that is at least ugly and at worst unmodular

– The only possible implementation makes O(n) calls to contains()– If a contains() call is worse than O(1), we lose performance

• Java, C++ support both ADT-style and OO-style abstractions– Ironically, OO languages helped make ADTs mainstream, and vice versa– Neither objects nor ADTs is “better” than the other

• They are design styles (or patterns) that are useful in different situations

36

Page 37: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Does Interoperability Matter?

• For data structures such as Set, maybe not– Maybe optimization benefits of ADTs dominate interoperability

“Although a program development support system must store many implementations of a type..., allowing multiple implementations within a single program seems less important.”

- A History of CLU [Liskov, 1993]

• But are data structures what OOP is really about?

37

Page 38: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Are Objects Really About Data Structures?

An object is “...a value exporting a procedural interface to data or behavior.” [Cook, 2009]

“a program execution is regarded as a physical model, simulating the behavior of either a real or imaginary part of the world”

[Madsen, Møller-Pedersen, Nygaard (and implicitly Dahl), 1993]

“The last thing you wanted any programmer to do is mess with internal state even if presented figuratively. Instead, the objects should be presented as sites of higher level behaviors more appropriate for use as dynamic components.” [Kay, 1993]

38

Page 39: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Objects as Servers

• Objects can implement data structures– Useful, but not their primary purpose

– Not a unique benefit of objects

• Kay [1993] writes of the “objects as server metaphor” in which every “object would be a server offering services” that are accessed via messages to the object.

• Intuitively, the server metaphor captures the characteristic of objects in which we are interested– Objects are little servers; we invoke services via methods

– Each object keeps track of its own behavior internally

39

Page 40: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Side Note: Distributed Objects• Kay’s work on objects was inspired by network servers

– Xerox PARC was a leader in networking research at the time

– Other OO languages took this quite literally

• Emerald provided a single distributed virtual machine– One program running on many server nodes

– Every object has a globally unique address

– Objects can refer to, or invoke methods of, remote objects

– Objects can move themselves to other nodes• Generally for efficiency purposes

– Fun problems in optimization, distributed GC

• Emerald, like Smalltalk, was beautiful but never caught on– The most attractive distributed programming model of which I know

– Practical challenges• Interoperation with systems not written in Emerald

• Abstractions like global address space, GC are nice, but also expensive

• Often distributed system programmers want lower-level control40

Page 41: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Objects provide Interoperability

• Let’s take the server metaphor to be the core of OO

• What are the benefits of servers?– Reynolds/Cook: objects provide interoperability

– But so do functions, type classes, generic programming, etc.

• What makes objects (as servers) unique?

41

Page 42: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Interoperability of Widgets• Consider a Widget-based GUI

– Originally developed in Smalltalk!

interface Widget {

Dimension getSize();

Dimension getPreferredSize();

void setSize(Dimension size);

void paint(Display display);

… /* more here */ } // based on ConstrainedVisual from Apache Pivot UI framework

• Nontrivial abstraction – not just paint()

– A single first-class function is not enough

42

Source: http://www.for-a.com/products/hvs300hs/hvs300hs.html

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 43: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Interoperability of Composite Widgets• Consider a Composite GUI

– Originally developed in Smalltalk!

class CompositeWidget implements Widget {

Dimension getSize();

Dimension getPreferredSize();

void setSize(Dimension size);

void paint(Display display);

void add(Widget widget)

… /* more here */ } // based on Container from Apache Pivot UI framework

• Nontrivial abstraction – not just paint()

– A single first-class function is not enough

• Composite needs to store diverse subcomponents in a list

– Can’t do this with type classes, generic programming

• Composite needs to invoke paint() uniformly on all subcomponents

– Also breaks type classes, generic programming43

Source: http://www.for-a.com/products/hvs300hs/hvs300hs.html

Object-oriented dispatchsupports interoperabilitybetween different Widgetsin a Composite

Page 44: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Design Leverage of ObjectsThe ability to define nontrivial abstractions that are modularly extensible, where instances of those extensions can interoperate in a first-class way.• Nontrivial abstractions

– An interface that provides at least two essential services

• Modular extensibility– New implementations not anticipated when the abstraction was designed

can be provided without changing the original abstraction

• First-class Interoperability– Interoperability of binary methods

• Such as adding a subcomponent to a composite

– First-class manipulation of different implementations• Such as putting subcomponents in a list

– Uniform treatment of different implementations• Such as invoking paint() on all subcomponents

44

Page 45: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Large-Scale Development Impact

• How might objects impact in-the-large software development?

• Some hints– We are likely looking for an approach to design

– We already know service abstractions are useful for GUIs

– Anecdotally, one can argue that GUIs drove OO

• Smalltalk, MacApp, Microsoft Foundation Classes, Java Applets, …

– What are these GUI designs an instance of?

• A likely candidate: software frameworks [Johnson, 1997]

45

Page 46: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Software Frameworks

• A framework is “the skeleton of an application that can be customized by an application developer” [Johnson, 1997]

• Frameworks uniquely provide architectural reuse– Reuse of “the edifice that ties components together”

[Johnson and Foote, 1988]

– Johnson [1997] argues can reduce development effort by 10x

• As a result, frameworks are ubiquitous– GUIs: Swing, SWT, .NET, GTK+

– Web: Rails, Django, .NET, Servlets, EJB

– Mobile: Android, Cocoa

– Big data: MapReduce, Hadoop

46OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 47: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Frameworks need Objects• Frameworks define abstractions that extensions implement

– The developer “supplies [the framework] with a set of components that provide the application specific behavior” [Johnson and Foote, 1988]

– Sometimes the application-specific behavior is just a function– More often, as we will see, these abstractions are nontrivial

• Frameworks require modular extensibility– Applications extend the framework without modifying its code

• Frameworks are typically distributed as binaries or bytecode• cf. Meyer’s [1988] open-closed principle

– Framework developers cannot anticipate the details of extensions• Though they do plan for certain kinds of extensions

• Frameworks require interoperability– Plugins often must interoperate with each other– Frameworks must dynamically manage diverse plugins– We have already seen this for GUI widgets – let’s look at other examples

47OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 48: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Web Frameworks: Java Servlets

• Nontrivial abstraction– Lifecycle methods for resource management

– Configuration controls

• Modular extensibility– Intent is to add new Servlets

• Interoperability required– Web server has a list of diverse Servlet implementations

– Dispatch is required to allow different Servlets to provide their own behavior

48

interface Servlet {void service(Request req, Response res);void init(ServletConfig config);void destroy();String getServletInfo();ServletConfig getServletConfig();

}

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 49: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Operating Systems: Linux

• Linux is an OO framework!– In terms of design—not implemented

in an OO language

• File systems as objects– Interface is a struct of function

pointers

– Allows file systems to interoperate

• E.g. symbolic links between file systems

• Not just file systems– Many core OS abstractions are extensible

– ~100 object-like abstractions in the kernel

49

ext2

ntfs

fat

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 50: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Operating Systems: Linux

• Linux is an OO framework!– In terms of design—not implemented

in an OO language

• File systems as objects– Interface is a struct of function

pointers

– Allows file systems to interoperate

• E.g. symbolic links between file systems

• Not just file systems– Many core OS abstractions are extensible

– ~100 Service abstractions in the kernel

50

ext2

ntfs

fat

People often miss this, or even deny it, but there are many examples of object-oriented programming in the kernel. Although the kernel devel-opers may shun C++ and other explicitly object-oriented languages, thinking in terms of objects is often useful. The VFS [Virtual File System] is a good example of how to do clean and efficient OOP in C, which is a language that lacks any OOP constructs.

- Robert Love, Linux Kernel Development (2nd Edition)

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 51: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Software Ecosystems• A software ecosystem is a “set of software solutions that

enable, support, and automate the activities...[of] actors in the associated social or business ecosystem” [Bosch, 2009]– Examples: iOS, Android, Windows, Microsoft Office, Eclipse, Amazon

Marketplace, …

• Ecosystems have enormous economic impact– Driven by network effects [Katz and Shapiro, 1985]

– Top 5 tech firms control or dominate an ecosystem• Apple, Microsft, IBM, Samsung, Google

• Ecosystems require interoperability– Critical to achieving benefit from network effects

– “the architecture provides a formalization of the rules of interoperability and hence teams can, to a large extent, operate independently” [Bosch, 2009]

51OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 52: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Mobile Devices: Android

• Network effects (apps) give Android value

• Apps build on each other– Example: contact managers

• Smartr Contacts is a drop-in replacement for the default contact manager

• Phone, email apps can use Smartr Contacts without preplanning

– Enabled by service abstraction interfaces

• Android keeps a list of heterogeneous ContentProvider implementations

52

class ContentProvider {abstract Cursor query(Uri uri, ...);abstract int insert(Uri uri, ContentValues vals);abstract Uri update(Uri uri, ContentValues vals, ...);abstract int delete(Uri uri, ...);... // other methods not shown

}

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 53: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

ADTs vs. Objects, Revisited

• What have we learned about objects?

• Especially compared to alternatives such as abstract types (ADTs)– cf. 15-150: functional programming languages focus on good support

for ADTs, but not (typically) objects

• ADTs are more useful in performance-critical algorithmic code

• Objects are more useful for large-scale program organization– Particularly when solving framework-like design problems

• We need both ADTs and objects!– Languages like Java provide adequate—though imperfect—support for

both

53

Page 54: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Conclusions: Why Objects Were Successful

• The essence of objects is dispatch

• Dispatch provides interoperability

• First-class interoperability is critical to frameworks and ecosystems

• Frameworks and ecosystems are economically critical to the software industry

• Likely a significant factor in objects’ success– Future study is warranted to validate the story above

– Other factors (psychology, benefits of inheritance) are worth exploring too

54OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich

Page 55: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

OO History Takeaways

• Origins in simulation and Hoare’s Record Classes

• Inheritance and virtual procedures in Simula 67

• Everything as an object in Smalltalk

• Smalltalk’s impact: GUIs, frameworks

• Role of dispatch, frameworks in adoption of OO technology

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich55

Page 56: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

Resources

• Squeak – a modern Smalltalk implementation– http://www.squeak.org/

– Alan C. Kay. The Early History of Smalltalk. Proc. History of Programming Languages, 1993. http://portal.acm.org/citation.cfm?id=155364

• GNU Simula– https://www.gnu.org/software/cim/

– An Introduction to Programming in Simula. Rob Pooley. http://www.macs.hw.ac.uk/~rjp/bookhtml/

• The Power of Interoperability: Why Objects Are Inevitable. Jonathan Aldrich. In Onward! Essays, 2013.– http://www.cs.cmu.edu/~aldrich/papers/objects-essay.pdf

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich56

Page 57: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

OO History Trivia Questions

• Name at least one of the designers of Simula or Smalltalk

• Multiple choice: the primary designer of Smalltalk compared objects to:– Records

– Functions

– Networked computers

– Cars

• Which of the following ideas were new in Simula 67?– Subclasses with inherited fields

– The ability to define subclasses separately from the superclass

– Dynamic dispatch

– Multiple inheritance

– Garbage collection

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich57

Page 58: OO History: Simulaand Smalltalkaldrich/courses/17-396/slides/oo-history.pdf• Need to store vehicles in a toll booth queue. • Want to store vehicles in a linked list to represent

More OO History Questions

• Explain how Smalltalk can add different kinds of numbers together, always producing the right kind of number as a result

• What feature of object-oriented programming was likely most important to its success?

OO HistoryLanguage Design and Prototyping

© 2020 Jonathan Aldrich58