Lecture Notes
developed at XEROX PARC in early 1970's by Alan Kay and colleagues as an environment to teach programming to children
influenced by both Simula and LISP
Smalltalk-72, Smalltalk-76, Smalltalk-80 (simply referred to as Smalltalk)
in Smalltalk, everything is an object (not so in C++ or Java)
even a class is an object
for instance, class FinancialHistory is the only object of class Meta-FinancialHistory
each object is an abstraction of a computer
was the first pure object-oriented language
it is completely consistent with the OO paradigm
Ruby is also pure
Java is almost pure
adopts an anthropomorphic programming model [PLP] p. 491 (i.e., the only way to affect computation is to pass messages to objects which then execute code (a method) in response to the message)
not just a language, a complete software development environment
requires a mouse which was developed at PARC for this
uses a simple, uniform model of the world akin to LISP
uses a simple uniform syntax, again, akin to LISP
uniformity and simplicity: everything is an object
typeless (akin to LISP): any name can be bound to any object; class membership is the only typing
supports dynamic polymorphism (i.e., code is associated with no particular type)
automatic garbage collection
only reference variables which are implicitly dereferenced
only supports single inheritance
strongly typed (akin to ML and Haskell), but at runtime
dynamic nature
typeless language (akin to LISP)
dynamic binding
supports dynamic polymorphism
supports reflection: ability to inspect and modify a program while it is running!
contributions:
a new paradigm (not just a new language)
influential in personal computing revolution and windowing systems
inspired and pioneered
the object-oriented paradigm,
the idea of personal computing, and
windowing systems and GUI's (mouse)
class names must begin with an UPPER CASE letter and method names begin with a lower case letter; convention in C++ and Java, but not enforced
be careful to distinguish between
Object: root class (capital O)
object: just some object
period (.) is the statement separator
up arrow is return (typed ^); if omitted, then current object returned
left arrow (←) is assignment (typed _)
text between single quotes is treated as a string
text between double quotes are considered comments
local variables introduced with pipe symbols (e.g., | temp |)
blocks: [ ... ] can be thought of as a closure and call-by-name parameter; allows Smalltalk to handle control in a purely OO fashion
sometimes called selectors
messages are written in postfix form
a colon precedes the argument to a message
unary
// C++ q.front() "Smalltalk" q front
keyword
// C++ q.enqueue(x) "Smalltalk" q enqueue: x // C++ table.insert(anItem, anIndex) "Smalltalk" table insert: anItem at: anIndex
binary: 2 + 3
in this manner Smalltalk programs read like English
Class activity/Quiz
Given the following class diagram, answer the Meta-Madness Quiz.
Simula, Smalltalk, Objective-C, Modula-3, Ada, Oberon support only single inheritance
C++, CLOS, and Python support multiple inheritance
`Java, C#, and Ruby provide a limited mix-in form of multiple inheritance, in which only one parent class is permitted to have fields' and the other is an interface
Reading Questions
What is Just-in-time compilation?
Why does Smalltalk support single (and not multiple) inheritance?
Why do you need to declare local variables if there are no static types?
How can you indicate that a method is private?
Why does 1+2*3 = 9?
How is a block like a lambda expression?
2+3 is not an expression!
2+3 is the message + sent to object 2 with argument object 3, requesting that it add 3 to itself and return the result (the object 5)
for loop is an object
allocated from the heap
deallocation is implicit using garbage collection akin to LISP
1 to: 5 do: [:i | (Transcript show: 'Hello World') cr] dialog _ FillInTheBlank request: 'How may I help you, Larry?'
Developing a Smalltalk program
involves extending or modifying the existing class hierarchy
can modify the existing class hierarchy (no need to always subclass)
increment
decrement
all user-defined classes are automatically placed into this
the root class is called Object
life begins at class Object
class: superclass, instance variables, and methods
no privacy control (simplistic/purity) of instance variables or methods, instance variables can only be accessed through methods (i.e., all instance variables private, all methods public)
self is the receiver (akin to this in C++ or Java)
super is the immediate super class
new is a class method
classes are objects of a metaclass class (which implements new)
new
^super new setInitialBalance: 0
initialize: amount
^super new setInitialBalance: amount
written in postfix form
concept of a block
statically scoped closures
similar to lambda expressions in LISP
for instance, (Smalltalk heart) ifTrue: [car honk] (expression is an object) [BIST]
value message (evaluates a block)
simulation
research
What can be done in pure OO languages, such as Smalltalk, which cannot be done with impure OO languages, such as C++ or Java?
META MADNESS QUIZ
The class hierarchy
Student superclass
Person superclass
Object superclass
The parallel metaclass hierarchy
Student class name
Student class superclass
Object class superclass
Class superclass
ClassDescription superclass
Behavior superclass
The metaclass hierarchy
Student class class
Person class class
Object class class
Class class class
ClassDescription class class
Behavior class class
Metaclass superclass
Metaclass superclass superclass
Final Question
Metaclass class class
SOLUTIONS
The class hierarchy
Person
Object
nil
The parallel metaclass hierarchy
‘Student class’
Person class
Class
ClassDescription
Behavior
Object
The metaclass hierarchy
Metaclass
Metaclass
Metaclass
Metaclass
Metaclass
Metaclass
ClassDescription
Behavior
Final Question
Metaclass