SmalltalkThe dynamic languageMohamed SamyAugust 2011samy2004@gmail.com
The Dynabook project - 1968●   Presented in the paper      "A Personal Computer for children of all ages"    by Alan C. Kay
The Dynabook project - 1968
The Dynabook project - 1968
The Dynabook project - 1968
The Dynabook project - 1968
The Dynabook project - 1968
The Dynabook project - 1968
Smalltalk●   One of the first OOP languages, greatly    influenced OOP●   Ideas transferred to C++, Objective-C, Java, C#,...
Pure OOP?●   What does a language like C++ do in non object-    oriented ways?    ●   Primitive data types like int, char,...
Small syntax●   Assignment:        a := 5●   Message sends:        obj message        obj messageWithArg: 12        obj me...
Small syntax●   Messages on top of messages:      2 squared factorial●   Message cascading:    window := ShellView new sho...
Small syntax●   Blocks      myFunc := [ MessageBox notify: I have arrived      mommy ]      myfunc value●   Blocks with ar...
Pure OOP?●   What does a language like C++ do in non object-    oriented ways?    ●   Primitive data types like int, char,...
Primitive types●   Integers, floats, fractions, booleans...etc are all    objects●   They even have a class hierarchy ^ ^●...
Control flow●   If    ●    cond ifTrue: [block]    ●    cond ifTrue: [block1] ifFalse: [block2]●   While/Until    ●    [co...
Lets create a whileNot loop●   1- Create a class MyLoop and define this method:    whileNot: cond do: action    cond value...
Symbols●   An expression like #abc represents an object●   Symbols guarantee that the same #... expression    always retur...
Pure OOP?●   What does a language like C++ do in non object-    oriented ways?    ●   Primitive data types like int, char,...
Processes & ContinuationsclockStep := [Processor sleep: 1000.(View desktop canvas)    font: (Font name: Arial pointSize: 3...
Processes & Continuations●   A process is an object and, like any other, can be    sent messages.●   It knows about its ca...
Pure OOP?●   What does a language like C++ do in non object-    oriented ways?    ●   Primitive data types like int, char,...
Secrets of the classes●   How was the class MyLoop created?      Object subclass: #MyLoop        instanceVariableNames:   ...
Classes are objects        MessageBox notify: 12 class printString        Console.WriteLine("{0}",12.GetType( ).ToString( ...
Classes are objects●   Classes are defined, modified at runtime●   Everything happens at runtime! No compile    time/runti...
Applications: Smalltalk●   Education    ●   eToys    ●   OpenCroquet●   Tools    ●   The Seaside web framework    ●   Aida...
Applications: Ideas●   Applying the concept to non-smalltalk applications:    ●   The web, social networks, ...etc are liv...
Upcoming SlideShare
Loading in...5
×

Smalltalk, the dynamic language

881

Published on

A tour of the Smalltalk language and pure OOP, with a focus on the ideas themselves and their influence on other tools.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
881
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Smalltalk, the dynamic language

  1. 1. SmalltalkThe dynamic languageMohamed SamyAugust 2011samy2004@gmail.com
  2. 2. The Dynabook project - 1968● Presented in the paper "A Personal Computer for children of all ages" by Alan C. Kay
  3. 3. The Dynabook project - 1968
  4. 4. The Dynabook project - 1968
  5. 5. The Dynabook project - 1968
  6. 6. The Dynabook project - 1968
  7. 7. The Dynabook project - 1968
  8. 8. The Dynabook project - 1968
  9. 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. 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. 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. 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. 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. 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. 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
  16. 16. Control flow● If ● cond ifTrue: [block] ● cond ifTrue: [block1] ifFalse: [block2]● While/Until ● [cond] whileTrue: [block] ● [cond] whileFalse: [cond]● Counting ● 5 timesRepeat: [ MessageBox notify: hi ] ● 1 to: 10 do: [ :a | MessageBox notify: a printString ] ● 1 to: 10 by: 2 do: [ :a | MessageBox notify: a printString ]
  17. 17. Lets 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- Lets test our method loop = MyLoop new. i:=0. loop whileNot: [ i=10] do : [i:= i+1]. MessageBox notify: i printString
  18. 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. 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
  20. 20. Processes & ContinuationsclockStep := [Processor sleep: 1000.(View desktop canvas) font: (Font name: Arial pointSize: 36) beBold; text: Time now printString at: 10@10; free]digitalClockProcess := [ clockStep repeat ] fork.
  21. 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. 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. 23. Secrets of the classes● How was the class MyLoop created? Object subclass: #MyLoop instanceVariableNames: classVariableNames: poolDictionaries: classInstanceVariableNames: ● Can we do this manually?
  24. 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. 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● Its like Photoshop + Interpreter● The IDE and application are one! ● e.g Debugging ● e.g Inspector ● Inspect & debug IDE!
  26. 26. Applications: Smalltalk● Education ● eToys ● OpenCroquet● Tools ● The Seaside web framework ● Aida/Web web framework● Commercial applications ● Auctomatic ● DabbleDB ● Teleplace
  27. 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)

×