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)