SlideShare a Scribd company logo
Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
Objects to the Roots:
Learning from beauty
Learning from beauty
S.Ducasse 2
Really?!
No primitive types
No hardcoded constructs for conditional
Only messages
Only objects
and this works?
I mean really?
Not even slow?
Can’t be real!
S.Ducasse 3
Motto
Let’s open our eyes, look, understand, and deeply
understand the underlying design aspects of object-
oriented programming...
S.Ducasse 4
Booleans
3 > 0
ifTrue: ['positive']
ifFalse: ['negative']
S.Ducasse 5
Booleans
3 > 0
ifTrue: ['positive']
ifFalse: ['negative']
'positive'
S.Ducasse 6
Yes ifTrue:ifFalse: is a message!
Weather isRaining
ifTrue: [self takeMyUmbrella]
ifFalse: [self takeMySunglasses]
ifTrue:ifFalse is sent to an object: a boolean!
S.Ducasse 7
Booleans
& | not
or: and: (lazy)
xor:
ifTrue:ifFalse:
ifFalse:ifTrue:
...
S.Ducasse 8
Lazy Logical Operators
false and: [1 error: 'crazy']
PrIt-> false and not an error
S.Ducasse 9
Yes! ifTrue:ifFalse: is a message send to a
Boolean.
But optimized by the compiler :)
S.Ducasse 10
Implementing not
Now you are good and you should implement it
Propose an implementation of not in a world
where you do not have Booleans
false not -> true
true not -> false
S.Ducasse 11
S.Ducasse 12
Implementing ifTrue:ifFalse:
Now you are good and you should implement it
Propose an implementation of not in a world
where you do not have Booleans
false ifTrue: [ 3 ] ifFalse: [ 5 ]
true ifTrue: [ 3 ] ifFalse: [ 5 ]
S.Ducasse 13
Boolean Objects
false and true are objects
described by classes
Boolean,True and False
S.Ducasse 14
Let’s the receiver decide!
S.Ducasse 15
Boolean>>not
“Class Boolean is an abstract class that implements
behavior common to true and false. Its subclasses are True
and False. Subclasses must implement methods for logical
operations &, not, controlling and:, or:, ifTrue:, ifFalse:,
ifTrue:ifFalse:, ifFalse:ifTrue:”
Boolean>>not
"Negation. Answer true if the receiver is false, answer false
if the receiver is true."
self subclassResponsibility
S.Ducasse 16
Not
false not -> true
true not -> false
Boolean>>not
"Negation. Answer true if the receiver is false, answer false if
the receiver is true.”
self subclassResponsibility
False>>not
"Negation -- answer true since the receiver is false."
^true
True>>not
"Negation--answer false since the receiver is true."
^false
S.Ducasse 17
| (Or)
• true | true -> true
• true | false -> true
• true | anything -> true
• false | true -> true
• false | false -> false
• false | anything -> anything
S.Ducasse 18
Boolean>> | aBoolean
Boolean>> | aBoolean
"Evaluating disjunction (OR). Evaluate the argument.
Answer true if either the receiver or the argument is
true."
self subclassResponsibility
S.Ducasse 19
False>> | aBoolean
false | true -> true
false | false -> false
false | anything -> anything
False>> | aBoolean
"Evaluating disjunction (OR) -- answer with the
argument, aBoolean."
^ aBoolean
S.Ducasse 20
True>> | aBoolean
true | true -> true
true | false -> true
true | anything -> true
True>> | aBoolean
"Evaluating disjunction (OR) -- answer true since the
receiver is true."
^ self
S.Ducasse 21
Boolean,True and False
S.Ducasse 22
Implementation Note
Note that theVirtual Machine shortcuts calls to
boolean such as condition for speed reason.
Virtual machines such asVisualWorks introduced a
kind of macro expansion, an optimisation for
essential methods and Just In Time (JIT)
compilation.A method is executed once and
afterwards it is compiled into native code. So the
second time it is invoked, the native code will be
executed.
S.Ducasse 23
S.Ducasse 24
Ok so what?
You will probably not implement another Boolean
classes
So is it really that totally useless?
S.Ducasse 25
Ternary logic
Boolean: true, false, unknown
S.Ducasse 26
More important...
Message sends act as case statements
S.Ducasse 27
OOP: the art of dispatching
Subclasses create your vocabulary
S.Ducasse 28
Avoid Conditional
Use objects and messages
VM dispatch is a conditional switch: Use it!
AntiIfCampaign
S.Ducasse 29
Summary
Messages act as a dispatcher
Avoid conditional

More Related Content

Similar to Dispatch (20)

PPT
Clojure slides
mcohen01
 
PDF
Becoming Functional Steps For Transforming Into A Functional Programmer Joshu...
chelliidzia
 
PPT
7 - OOP - OO Concepts
The World of Smalltalk
 
DOCX
NDSU CSCI 717Software ConstructionDefensive Programming.docx
vannagoforth
 
PPT
Debugging VisualWorks
The World of Smalltalk
 
PDF
Static Analysis and Verification of C Programs
New York City College of Technology Computer Systems Technology Colloquium
 
PDF
Intro to io
jtregunna
 
PPT
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
PDF
Os Harrison
oscon2007
 
PPTX
Structure and interpretation of computer programs modularity, objects, and ...
bdemchak
 
PPT
Stoop 300-block optimizationinvw
The World of Smalltalk
 
PPT
Javascript
Sunil Thakur
 
PDF
Beyond Ruby (RubyConf Argentina 2011)
Konstantin Haase
 
KEY
Refactoring RIA Unleashed 2011
Jesse Warden
 
PDF
(chapter 3) A Concise and Practical Introduction to Programming Algorithms in...
Frank Nielsen
 
PPT
5 - OOP - Smalltalk in a Nutshell (c)
The World of Smalltalk
 
PDF
Functional programming
ijcd
 
PDF
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Codemotion
 
PPT
Stoop 422-naming idioms
The World of Smalltalk
 
PPT
Stoop 421-design heuristics
The World of Smalltalk
 
Clojure slides
mcohen01
 
Becoming Functional Steps For Transforming Into A Functional Programmer Joshu...
chelliidzia
 
7 - OOP - OO Concepts
The World of Smalltalk
 
NDSU CSCI 717Software ConstructionDefensive Programming.docx
vannagoforth
 
Debugging VisualWorks
The World of Smalltalk
 
Intro to io
jtregunna
 
Stoop 414-smalltalk elementsofdesign
The World of Smalltalk
 
Os Harrison
oscon2007
 
Structure and interpretation of computer programs modularity, objects, and ...
bdemchak
 
Stoop 300-block optimizationinvw
The World of Smalltalk
 
Javascript
Sunil Thakur
 
Beyond Ruby (RubyConf Argentina 2011)
Konstantin Haase
 
Refactoring RIA Unleashed 2011
Jesse Warden
 
(chapter 3) A Concise and Practical Introduction to Programming Algorithms in...
Frank Nielsen
 
5 - OOP - Smalltalk in a Nutshell (c)
The World of Smalltalk
 
Functional programming
ijcd
 
Mike Kotsur - What can philosophy teach us about programming - Codemotion Ams...
Codemotion
 
Stoop 422-naming idioms
The World of Smalltalk
 
Stoop 421-design heuristics
The World of Smalltalk
 

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-smells
The World of Smalltalk
 
PPT
Stoop sed-sharing ornot
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
 
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-smells
The World of Smalltalk
 
Stoop sed-sharing ornot
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
 
Ad

Recently uploaded (20)

PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
I AM MALALA The Girl Who Stood Up for Education and was Shot by the Taliban...
Beena E S
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
Dimensions of Societal Planning in Commonism
StefanMz
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
community health nursing question paper 2.pdf
Prince kumar
 
The-Ever-Evolving-World-of-Science (1).pdf/7TH CLASS CURIOSITY /1ST CHAPTER/B...
Sandeep Swamy
 
Ad

Dispatch