SlideShare a Scribd company logo
S.Ducasse 1
QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture.
Stéphane Ducasse
Stephane.Ducasse@univ-savoie.fr
http://www.listic.univ-savoie.fr/~ducasse/
Smalltalk in a Nutshell
S.Ducasse 2
License: CC-Attribution-ShareAlike 2.0
http://creativecommons.org/licenses/by-sa/2.0/
S.Ducasse 3
Goals
• Syntax in a Nutshell
• OO Model in a Nutshell
S.Ducasse 4
Smalltalk OO Model
• ***Everything*** is an object
® Only message passing
® Only late binding
• Instance variables are private to the object
• Methods are public
• Everything is a pointer
• Garbage collector
• Single inheritance between classes
• Only message passing between objects
S.Ducasse 5
Complete Syntax on a PostCard
exampleWithNumber: x
“A method that illustrates every part of Smalltalk method syntax except primitives. It
has unary, binary, and key word messages, declares arguments and temporaries (but
not block temporaries), accesses a global variable (but not and instance variable), uses
literals (array, character, symbol, string, integer, float), uses the pseudo variable true
false, nil, self, and super, and has sequence, assignment, return and cascade. It has both
zero argument and one argument blocks. It doesn’t do anything useful, though”
|y|
true & false not & (nil isNil) ifFalse: [self halt].
y := self size + super size.
#($a #a ‘a’ 1 1.0)
do: [:each | Transcript
show: (each class name);
show: (each printString);
show:‘ ‘].
^ x < y
S.Ducasse 6
Language Constructs
^ return
“ comments
# symbol or array
‘ string
[ ] block or byte array
. separator and not terminator (or namespace access inVW)
; cascade (sending several messages to the same instance)
| local or block variable
:= assignment
$ character
: end of selector name
e, r number exponent or radix
! file element separator
<primitive: ...> forVM primitive calls
S.Ducasse 7
Syntax
comment: “a comment”
character: $c $h $a $r $a $c $t $e $r $s $# $@
string: ‘a nice string’ ‘lulu’ ‘l’’idiot’
symbol: #mac #+
array: #(1 2 3 (1 3) $a 4)
byte array: #[1 2 3]
integer: 1, 2r101
real: 1.5, 6.03e-34,4, 2.4e7
float: 1/33
boolean: true, false
point: 10@120
Note that @ is not an element of the syntax, but just a message sent to a
number.This is the same for /, bitShift, ifTrue:, do: ...
S.Ducasse 8
Syntax in a Nutshell (II)
assigment: var := aValue
block: [:var ||tmp| expr...]
temporary variable: |tmp|
block variable: :var
unary message: receiver selector
binary message: receiver selector argument
keyword based: receiver keyword1: arg1 keyword2:
arg2...
cascade: message ; selector ...
separator: message . message
result: ^
parenthesis: (...)
S.Ducasse 9
Messages vs. a predefined Syntax
• In Java, C, C++,Ada constructs like >>, if, for, etc. are
hardcoded into the language grammar
• In Smalltalk there are just messages defined on objects
• (>>) bitShift: is just a message sent to numbers
– 10 bitShift: 2
• (if) ifTrue: is just messages sent to a boolean
– (1> x) ifTrue:
• (for) do:, to:do: are just messages to collections or
numbers
– #(a b c d) do: [:each |Transcript show: each ; cr]
– 1 to: 10 do: [:i |Transcript show: each printString; cr]
• Minimal parsing
• Language is extensible
S.Ducasse 10
• Class Definition:A message sent to a namespace
Smalltalk defineClass: #NameOfClass
superclass: #{NameOfSuperclass}
indexedType: #none
private: false
instanceVariableNames: ''
classInstanceVariableNames: ''
imports: ''
category: 'Browser-Commands'
Class Definition inVW
S.Ducasse 11
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1'
classVariableNames: 'classVarName1'
poolDictionaries: ''
category: 'LAN'
Class Definition in Squeak
S.Ducasse 12
Method Definition
• Normally defined in a browser or (by directly invoking
the compiler)
• Methods are public
• Always return self
Node>>accept: thePacket
"If the packet is addressed to me, print it.
Else just behave like a normal node"
(thePacket isAddressedTo: self)
ifTrue: [self print: thePacket]
ifFalse: [super accept: thePacket]
S.Ducasse 13
• ‘1’,‘abc’
• Basic class creation messages are
new, new:,
basicNew, basicNew:
Monster new
• Class specific message creation (messages sent to
classes)
Tomagoshi withHunger: 10
S.Ducasse 14
Messages and their Composition
• Three kinds of messages
– Unary: Node new
– Binary: 1 + 2, 3@4
– Keywords: aTomagoshi eat: #cooky furiously: true
– Message Priority
• (Msg) > unary > binary > keywords
• Same Level from left to right
• Example:
• (10@0 extent: 10@100) bottomRight
• s isNil ifTrue: [ self halt ]
S.Ducasse 15
• Anonymous method
• Passed as method argument or stored
• Functions
fct(x)= x*x+3, fct(2).
fct :=[:x| x * x + 3]. fct value: 2
Integer>>factorial
tmp:= 1.
2 to: self do: [:i| tmp := tmp * i]
#(1 2 3) do: [:each | Transcript show: each printString ; cr]
Blocks
S.Ducasse 16
Summary
Objects and Messages
Three kinds of messages
unary
binary
keywords
Block: a.k.a innerclass or closures or lambda
Unary>Binary>Keywords
S.Ducasse 17
Goals
• Syntax in a Nutshell
• OO Model in a Nutshell
S.Ducasse 18
Instance and Class
• Only one model
• Uniformly applied
• Classes are objects too
S.Ducasse 19
Lookup…Class + Inheritance
1
2
S.Ducasse 20
Classes are objects too
• Instance creation is just a message send to a ... Class
• Same method lookup than with any other objects
• a Class is the single instance of amanonymous class
• Point is the single instance of Point class
S.Ducasse 21
Class Parallel Inheritance
S.Ducasse 22
Lookup and Class Methods
1
2
1
2
Workstation withName: ‘BigMac’
aWorkstation
name
S.Ducasse 23
About the Buttons
S.Ducasse 24
Summary
- Everything is an object
- One single model
- Single inheritance
- Public methods
- Private attribute
- Classes are simply objects too
- Class is instance of another class
- One unique method lookup
look in the class of the receiver

More Related Content

What's hot (18)

PPT
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
PDF
Rust: Unlocking Systems Programming
C4Media
 
PPT
Python in 90mins
Larry Cai
 
PPT
Stoop 303-advanced blocks
The World of Smalltalk
 
PDF
Rust "Hot or Not" at Sioux
nikomatsakis
 
PPTX
Development of anonymous networks based on cryptography
Md. Hasibur Rashid
 
PDF
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
PDF
Rust: Reach Further (from QCon Sao Paolo 2018)
nikomatsakis
 
PPTX
Lecture 2 Message Authentication
University of Rome "La Sapienza"
 
PDF
Architecture of MessagePack
Sadayuki Furuhashi
 
PPT
Stoop 300-block optimizationinvw
The World of Smalltalk
 
ODP
Nový Email.cz
seznamVyvojari
 
PPT
Lecture4
FALLEE31188
 
PPT
Lecture4
rajesh0ks
 
PDF
An introduction to Rust: the modern programming language to develop safe and ...
Claudio Capobianco
 
PPT
Chapter 8 - Computer Networking a top-down Approach 7th
Andy Juan Sarango Veliz
 
PPT
Computer security
Harry Potter
 
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Rust: Unlocking Systems Programming
C4Media
 
Python in 90mins
Larry Cai
 
Stoop 303-advanced blocks
The World of Smalltalk
 
Rust "Hot or Not" at Sioux
nikomatsakis
 
Development of anonymous networks based on cryptography
Md. Hasibur Rashid
 
Introduction to Ruby Programming Language
Nicolò Calcavecchia
 
Rust: Reach Further (from QCon Sao Paolo 2018)
nikomatsakis
 
Lecture 2 Message Authentication
University of Rome "La Sapienza"
 
Architecture of MessagePack
Sadayuki Furuhashi
 
Stoop 300-block optimizationinvw
The World of Smalltalk
 
Nový Email.cz
seznamVyvojari
 
Lecture4
FALLEE31188
 
Lecture4
rajesh0ks
 
An introduction to Rust: the modern programming language to develop safe and ...
Claudio Capobianco
 
Chapter 8 - Computer Networking a top-down Approach 7th
Andy Juan Sarango Veliz
 
Computer security
Harry Potter
 

Viewers also liked (6)

PPT
8 - OOP - Smalltalk Model
The World of Smalltalk
 
PPT
10 - OOP - Inheritance (b)
The World of Smalltalk
 
PPT
3 - OOP - VisualWorks (a)
The World of Smalltalk
 
PPT
Double Dispatch
The World of Smalltalk
 
PPT
11 - OOP - Numbers
The World of Smalltalk
 
PPT
Stoop 413-abstract classes
The World of Smalltalk
 
8 - OOP - Smalltalk Model
The World of Smalltalk
 
10 - OOP - Inheritance (b)
The World of Smalltalk
 
3 - OOP - VisualWorks (a)
The World of Smalltalk
 
Double Dispatch
The World of Smalltalk
 
11 - OOP - Numbers
The World of Smalltalk
 
Stoop 413-abstract classes
The World of Smalltalk
 
Ad

Similar to 5 - OOP - Smalltalk in a Nutshell (b) (20)

PPT
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 
PPT
8 - OOP - Syntax & Messages
The World of Smalltalk
 
PPT
9 - OOP - Smalltalk Classes (a)
The World of Smalltalk
 
PPT
9 - OOP - Smalltalk Classes (b)
The World of Smalltalk
 
PPT
Stoop 304-metaclasses
The World of Smalltalk
 
PDF
Pharo: Syntax in a Nutshell
Marcus Denker
 
PDF
2013 lecture-02-syntax shortnewcut
Pharo
 
KEY
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 
PDF
EKON 12 Closures Coding
Max Kleiner
 
PPT
6 - OOP - LAN Example
The World of Smalltalk
 
PPT
Stoop 305-reflective programming5
The World of Smalltalk
 
PPT
Visual basic intoduction
mohamedsaad24
 
PPT
mooc_presentataion_mayankmanral on the subject puthon
garvitbisht27
 
PDF
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
CHOOSE
 
PPT
Stoop sed-smells
The World of Smalltalk
 
PPT
3 - OOP - Runtime
The World of Smalltalk
 
PDF
Introduction to Elixir
Diacode
 
PPTX
Scala 3 Is Coming: Martin Odersky Shares What To Know
Lightbend
 
PPT
10 - OOP - Inheritance (a)
The World of Smalltalk
 
4 - OOP - Taste of Smalltalk (VisualWorks)
The World of Smalltalk
 
8 - OOP - Syntax & Messages
The World of Smalltalk
 
9 - OOP - Smalltalk Classes (a)
The World of Smalltalk
 
9 - OOP - Smalltalk Classes (b)
The World of Smalltalk
 
Stoop 304-metaclasses
The World of Smalltalk
 
Pharo: Syntax in a Nutshell
Marcus Denker
 
2013 lecture-02-syntax shortnewcut
Pharo
 
Pharo, an innovative and open-source Smalltalk
Serge Stinckwich
 
EKON 12 Closures Coding
Max Kleiner
 
6 - OOP - LAN Example
The World of Smalltalk
 
Stoop 305-reflective programming5
The World of Smalltalk
 
Visual basic intoduction
mohamedsaad24
 
mooc_presentataion_mayankmanral on the subject puthon
garvitbisht27
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
CHOOSE
 
Stoop sed-smells
The World of Smalltalk
 
3 - OOP - Runtime
The World of Smalltalk
 
Introduction to Elixir
Diacode
 
Scala 3 Is Coming: Martin Odersky Shares What To Know
Lightbend
 
10 - OOP - Inheritance (a)
The World of Smalltalk
 
Ad

More from The World of Smalltalk (20)

PDF
05 seaside canvas
The World of Smalltalk
 
PPT
99 questions
The World of Smalltalk
 
PPT
12 virtualmachine
The World of Smalltalk
 
PPT
11 bytecode
The World of Smalltalk
 
PPT
10 reflection
The World of Smalltalk
 
PPT
09 metaclasses
The World of Smalltalk
 
PPT
08 refactoring
The World of Smalltalk
 
PPT
07 bestpractice
The World of Smalltalk
 
PPT
06 debugging
The World of Smalltalk
 
PPT
05 seaside
The World of Smalltalk
 
PPT
03 standardclasses
The World of Smalltalk
 
PPT
Stoop sed-class initialization
The World of Smalltalk
 
PPT
Stoop sed-class initialization
The World of Smalltalk
 
PPT
Stoop metaclasses
The World of Smalltalk
 
PPT
Stoop ed-unit ofreuse
The World of Smalltalk
 
PPT
Stoop ed-subtyping subclassing
The World of Smalltalk
 
PPT
Stoop ed-some principles
The World of Smalltalk
 
05 seaside canvas
The World of Smalltalk
 
12 virtualmachine
The World of Smalltalk
 
10 reflection
The World of Smalltalk
 
09 metaclasses
The World of Smalltalk
 
08 refactoring
The World of Smalltalk
 
07 bestpractice
The World of Smalltalk
 
03 standardclasses
The World of Smalltalk
 
Stoop sed-class initialization
The World of Smalltalk
 
Stoop sed-class initialization
The World of Smalltalk
 
Stoop metaclasses
The World of Smalltalk
 
Stoop ed-unit ofreuse
The World of Smalltalk
 
Stoop ed-subtyping subclassing
The World of Smalltalk
 
Stoop ed-some principles
The World of Smalltalk
 

Recently uploaded (20)

PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
PPT
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
PPTX
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
PPTX
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PDF
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
DRUGS USED IN THERAPY OF SHOCK, Shock Therapy, Treatment or management of shock
Rajshri Ghogare
 
Electrophysiology_of_Heart. Electrophysiology studies in Cardiovascular syste...
Rajshri Ghogare
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Unlock the Power of Cursor AI: MuleSoft Integrations
Veera Pallapu
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
TOP 10 AI TOOLS YOU MUST LEARN TO SURVIVE IN 2025 AND ABOVE
digilearnings.com
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
John Keats introduction and list of his important works
vatsalacpr
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 

5 - OOP - Smalltalk in a Nutshell (b)

  • 1. S.Ducasse 1 QuickTime™ and aTIFF (Uncompressed) decompressorare needed to see this picture. Stéphane Ducasse [email protected] http://www.listic.univ-savoie.fr/~ducasse/ Smalltalk in a Nutshell
  • 2. S.Ducasse 2 License: CC-Attribution-ShareAlike 2.0 http://creativecommons.org/licenses/by-sa/2.0/
  • 3. S.Ducasse 3 Goals • Syntax in a Nutshell • OO Model in a Nutshell
  • 4. S.Ducasse 4 Smalltalk OO Model • ***Everything*** is an object ® Only message passing ® Only late binding • Instance variables are private to the object • Methods are public • Everything is a pointer • Garbage collector • Single inheritance between classes • Only message passing between objects
  • 5. S.Ducasse 5 Complete Syntax on a PostCard exampleWithNumber: x “A method that illustrates every part of Smalltalk method syntax except primitives. It has unary, binary, and key word messages, declares arguments and temporaries (but not block temporaries), accesses a global variable (but not and instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variable true false, nil, self, and super, and has sequence, assignment, return and cascade. It has both zero argument and one argument blocks. It doesn’t do anything useful, though” |y| true & false not & (nil isNil) ifFalse: [self halt]. y := self size + super size. #($a #a ‘a’ 1 1.0) do: [:each | Transcript show: (each class name); show: (each printString); show:‘ ‘]. ^ x < y
  • 6. S.Ducasse 6 Language Constructs ^ return “ comments # symbol or array ‘ string [ ] block or byte array . separator and not terminator (or namespace access inVW) ; cascade (sending several messages to the same instance) | local or block variable := assignment $ character : end of selector name e, r number exponent or radix ! file element separator <primitive: ...> forVM primitive calls
  • 7. S.Ducasse 7 Syntax comment: “a comment” character: $c $h $a $r $a $c $t $e $r $s $# $@ string: ‘a nice string’ ‘lulu’ ‘l’’idiot’ symbol: #mac #+ array: #(1 2 3 (1 3) $a 4) byte array: #[1 2 3] integer: 1, 2r101 real: 1.5, 6.03e-34,4, 2.4e7 float: 1/33 boolean: true, false point: 10@120 Note that @ is not an element of the syntax, but just a message sent to a number.This is the same for /, bitShift, ifTrue:, do: ...
  • 8. S.Ducasse 8 Syntax in a Nutshell (II) assigment: var := aValue block: [:var ||tmp| expr...] temporary variable: |tmp| block variable: :var unary message: receiver selector binary message: receiver selector argument keyword based: receiver keyword1: arg1 keyword2: arg2... cascade: message ; selector ... separator: message . message result: ^ parenthesis: (...)
  • 9. S.Ducasse 9 Messages vs. a predefined Syntax • In Java, C, C++,Ada constructs like >>, if, for, etc. are hardcoded into the language grammar • In Smalltalk there are just messages defined on objects • (>>) bitShift: is just a message sent to numbers – 10 bitShift: 2 • (if) ifTrue: is just messages sent to a boolean – (1> x) ifTrue: • (for) do:, to:do: are just messages to collections or numbers – #(a b c d) do: [:each |Transcript show: each ; cr] – 1 to: 10 do: [:i |Transcript show: each printString; cr] • Minimal parsing • Language is extensible
  • 10. S.Ducasse 10 • Class Definition:A message sent to a namespace Smalltalk defineClass: #NameOfClass superclass: #{NameOfSuperclass} indexedType: #none private: false instanceVariableNames: '' classInstanceVariableNames: '' imports: '' category: 'Browser-Commands' Class Definition inVW
  • 11. S.Ducasse 11 NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'classVarName1' poolDictionaries: '' category: 'LAN' Class Definition in Squeak
  • 12. S.Ducasse 12 Method Definition • Normally defined in a browser or (by directly invoking the compiler) • Methods are public • Always return self Node>>accept: thePacket "If the packet is addressed to me, print it. Else just behave like a normal node" (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]
  • 13. S.Ducasse 13 • ‘1’,‘abc’ • Basic class creation messages are new, new:, basicNew, basicNew: Monster new • Class specific message creation (messages sent to classes) Tomagoshi withHunger: 10
  • 14. S.Ducasse 14 Messages and their Composition • Three kinds of messages – Unary: Node new – Binary: 1 + 2, 3@4 – Keywords: aTomagoshi eat: #cooky furiously: true – Message Priority • (Msg) > unary > binary > keywords • Same Level from left to right • Example: • (10@0 extent: 10@100) bottomRight • s isNil ifTrue: [ self halt ]
  • 15. S.Ducasse 15 • Anonymous method • Passed as method argument or stored • Functions fct(x)= x*x+3, fct(2). fct :=[:x| x * x + 3]. fct value: 2 Integer>>factorial tmp:= 1. 2 to: self do: [:i| tmp := tmp * i] #(1 2 3) do: [:each | Transcript show: each printString ; cr] Blocks
  • 16. S.Ducasse 16 Summary Objects and Messages Three kinds of messages unary binary keywords Block: a.k.a innerclass or closures or lambda Unary>Binary>Keywords
  • 17. S.Ducasse 17 Goals • Syntax in a Nutshell • OO Model in a Nutshell
  • 18. S.Ducasse 18 Instance and Class • Only one model • Uniformly applied • Classes are objects too
  • 19. S.Ducasse 19 Lookup…Class + Inheritance 1 2
  • 20. S.Ducasse 20 Classes are objects too • Instance creation is just a message send to a ... Class • Same method lookup than with any other objects • a Class is the single instance of amanonymous class • Point is the single instance of Point class
  • 22. S.Ducasse 22 Lookup and Class Methods 1 2 1 2 Workstation withName: ‘BigMac’ aWorkstation name
  • 24. S.Ducasse 24 Summary - Everything is an object - One single model - Single inheritance - Public methods - Private attribute - Classes are simply objects too - Class is instance of another class - One unique method lookup look in the class of the receiver