9. Smalltalk
● One of the first OOP languages, greatly
influenced OOP
● Ideas transferred to C++, Objective-C, Java, C#,
Ruby, Python, Dylan, ...etc...etc
● Has intellectual 'children' like Self, which in turn
influenced IO, JavaScript, and Newspeak
● Commercial implementations:
● VisualWorks, Dolphin Smalltalk, VA Smalltalk
● Open source implementations
● Squeak, Pharo, GNU Smalltalk
10. Pure OOP?
● What does a language like C++ do in non object-
oriented ways?
● Primitive data types like int, char, float...
● Control flow like if, while, for
● Functions
● Function names
● Classes (while they can create objects, they are not
objects).
● The call stack
● Processes/threads
● ...etc
11. Small syntax
● Assignment:
a := 5
● Message sends:
obj message
obj messageWithArg: 12
obj messageWithArgA: 12 argB: 13
obj1 + obj2 / obj3
● Note that 1 + 3 * 5 evaluates to 20, since + , * are
message sends like any other.
12. Small syntax
● Messages on top of messages:
2 squared factorial
● Message cascading:
window := ShellView new show.
window
position: 80@80;
extent: 320@90;
backcolor: Color blue;
caption: 'Test Window'.
13. Small syntax
● Blocks
myFunc := [ MessageBox notify: 'I have arrived
mommy' ]
myfunc value
● Blocks with args
myFunc := [ :x | MessageBox notify:
'I have arrived ' , x]
myFunc value: 'Tamer'
myFunc := [ :x :y | x + y ]
myFunc value: 12 value: 13
14. Pure OOP?
● What does a language like C++ do in non object-
oriented ways?
● Primitive data types like int, char, float...
● Control flow like if, while, for
● Functions
● Function names
● Classes (while they can create objects, they are not
objects).
● The call stack
● Processes/threads
● ...etc
15. Primitive types
● Integers, floats, fractions, booleans...etc are all
objects
● They even have a class hierarchy ^ ^
● The hierarchy allows e.g switching between
different integral types during program execution,
making use of the dynamic typing nature of the
language.
● Consider
5 factorial class
100 factorial class
17. Let's create a 'whileNot' loop
● 1- Create a class MyLoop and define this method:
whileNot: cond do: action
cond value ifFalse: [action value.
self whileNot: cond do: action ]
● 2- Let's test our method
loop = MyLoop new.
i:=0.
loop whileNot: [ i=10] do : [i:= i+1].
MessageBox notify: i printString
18. Symbols
● An expression like #abc represents an object
● Symbols guarantee that the same #... expression
always returns the same object
● This guarantee makes comparing symbols very
fast (compare references instead of strings)
● Class names, message selectors, ...etc are
symbols
● The benefits of this are related to the dynamic
nature of the language, and will appear shortly
19. Pure OOP?
● What does a language like C++ do in non object-
oriented ways?
● Primitive data types like int, char, float...
● Control flow like if, while, for
● Functions
● Function names
● Classes (while they can create objects, they are not
objects).
● The call stack
● Processes/threads
● ...etc
21. Processes & Continuations
● A process is an object and, like any other, can be
sent messages.
● It knows about its call stack, Smalltalk has support
for continuations
● This has a lot of uses...
● Debugging
● Distributed computing
● Continuation-based web frameworks like Seaside
●
...
22. Pure OOP?
● What does a language like C++ do in non object-
oriented ways?
● Primitive data types like int, char, float...
● Control flow like if, while, for
● Functions
● Function names
● Classes (while they can create objects, they are not
objects).
● The call stack
● Processes/threads
● ...etc
23. Secrets of the classes
● How was the class MyLoop created?
Object subclass: #MyLoop
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
classInstanceVariableNames: ''
● Can we do this manually?
24. Classes are objects
MessageBox notify: 12 class printString
Console.WriteLine("{0}",12.GetType( ).ToString( ))
System.out.println(myObj.getClass( ))
● Reflection: The program can ask for information
about its own classes, methods, fields...etc
● Useful for metaprogramming, many applications
● Automatic serialization
● Generation of GUI
● Factories
● ...etc
25. Classes are objects
● Classes are defined, modified at runtime
● Everything happens at runtime! No compile
time/runtime distinction.
● But methods are compiled, into bytecode or JITed
● It's like Photoshop + Interpreter
● The IDE and application are one!
● e.g Debugging
● e.g Inspector
● Inspect & debug IDE!
26. Applications: Smalltalk
● Education
● eToys
● OpenCroquet
● Tools
● The Seaside web framework
● Aida/Web web framework
● Commercial applications
● Auctomatic
● DabbleDB
● Teleplace
27. Applications: Ideas
● Applying the concept to non-smalltalk applications:
● The web, social networks, ...etc are live applications
that grow without stopping
● The web-browser itself as a live environment
● A new generation of IDEs
● Creative tools with a programming aspect
● Real tools influenced by Smalltalk:
● Objective-C (iPhone, iPad, Mac applications)
● Java/ .net
● Eclipse
● Firefox 6.0 Scratchpad (demo)