• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Smalltalk, the dynamic language
 

Smalltalk, the dynamic language

on

  • 1,101 views

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

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

Statistics

Views

Total Views
1,101
Views on SlideShare
1,097
Embed Views
4

Actions

Likes
0
Downloads
4
Comments
0

2 Embeds 4

https://twitter.com 3
http://twitter.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Smalltalk, the dynamic language Smalltalk, the dynamic language Presentation Transcript

    • 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#, 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
    • 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
    • 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.
    • 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.
    • 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
    • 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
    • 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
    • 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 ]
    • 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
    • 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
    • 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
    • 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.
    • 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 ● ...
    • 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
    • Secrets of the classes● How was the class MyLoop created? Object subclass: #MyLoop instanceVariableNames: classVariableNames: poolDictionaries: classInstanceVariableNames: ● Can we do this manually?
    • 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
    • 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!
    • Applications: Smalltalk● Education ● eToys ● OpenCroquet● Tools ● The Seaside web framework ● Aida/Web web framework● Commercial applications ● Auctomatic ● DabbleDB ● Teleplace
    • 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)