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

PDF
Concurrency in Smalltalk -- Beyond Threads
PPT
9 - OOP - Smalltalk Classes (b)
PDF
05 seaside canvas
PPT
PPT
12 virtualmachine
PPT
PPT
10 reflection
Concurrency in Smalltalk -- Beyond Threads
9 - OOP - Smalltalk Classes (b)
05 seaside canvas
12 virtualmachine
10 reflection

More from The World of Smalltalk (20)

PPT
09 metaclasses
PPT
08 refactoring
PPT
07 bestpractice
PPT
PPT
PPT
03 standardclasses
PPT
Stoop sed-smells
PPT
Stoop sed-sharing ornot
PPT
Stoop sed-class initialization
PPT
Stoop sed-class initialization
PPT
Stoop metaclasses
PPT
Stoop ed-unit ofreuse
PPT
Stoop ed-subtyping subclassing
PPT
Stoop ed-some principles
PPT
PPT
Stoop ed-inheritance composition
PPT
Stoop ed-frameworks
09 metaclasses
08 refactoring
07 bestpractice
03 standardclasses
Stoop sed-smells
Stoop sed-sharing ornot
Stoop sed-class initialization
Stoop sed-class initialization
Stoop metaclasses
Stoop ed-unit ofreuse
Stoop ed-subtyping subclassing
Stoop ed-some principles
Stoop ed-inheritance composition
Stoop ed-frameworks
Ad

Recently uploaded (20)

PDF
English Textual Question & Ans (12th Class).pdf
PDF
AI-driven educational solutions for real-life interventions in the Philippine...
PDF
Environmental Education MCQ BD2EE - Share Source.pdf
PPTX
Unit 4 Computer Architecture Multicore Processor.pptx
PDF
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
PDF
CRP102_SAGALASSOS_Final_Projects_2025.pdf
PPTX
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
PDF
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
PPTX
Core Concepts of Personalized Learning and Virtual Learning Environments
PDF
Complications of Minimal Access-Surgery.pdf
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
PDF
Hazard Identification & Risk Assessment .pdf
PPTX
Education and Perspectives of Education.pptx
PDF
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
PDF
IP : I ; Unit I : Preformulation Studies
PDF
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
PDF
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
DOCX
Cambridge-Practice-Tests-for-IELTS-12.docx
PPTX
B.Sc. DS Unit 2 Software Engineering.pptx
English Textual Question & Ans (12th Class).pdf
AI-driven educational solutions for real-life interventions in the Philippine...
Environmental Education MCQ BD2EE - Share Source.pdf
Unit 4 Computer Architecture Multicore Processor.pptx
BP 704 T. NOVEL DRUG DELIVERY SYSTEMS (UNIT 1)
CRP102_SAGALASSOS_Final_Projects_2025.pdf
DRUGS USED FOR HORMONAL DISORDER, SUPPLIMENTATION, CONTRACEPTION, & MEDICAL T...
Τίμαιος είναι φιλοσοφικός διάλογος του Πλάτωνα
Core Concepts of Personalized Learning and Virtual Learning Environments
Complications of Minimal Access-Surgery.pdf
A powerpoint presentation on the Revised K-10 Science Shaping Paper
MBA _Common_ 2nd year Syllabus _2021-22_.pdf
Hazard Identification & Risk Assessment .pdf
Education and Perspectives of Education.pptx
BP 505 T. PHARMACEUTICAL JURISPRUDENCE (UNIT 1).pdf
IP : I ; Unit I : Preformulation Studies
Myanmar Dental Journal, The Journal of the Myanmar Dental Association (2013).pdf
David L Page_DCI Research Study Journey_how Methodology can inform one's prac...
Cambridge-Practice-Tests-for-IELTS-12.docx
B.Sc. DS Unit 2 Software Engineering.pptx
Ad

Dispatch

  • 1. 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
  • 2. 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!
  • 3. S.Ducasse 3 Motto Let’s open our eyes, look, understand, and deeply understand the underlying design aspects of object- oriented programming...
  • 4. S.Ducasse 4 Booleans 3 > 0 ifTrue: ['positive'] ifFalse: ['negative']
  • 5. S.Ducasse 5 Booleans 3 > 0 ifTrue: ['positive'] ifFalse: ['negative'] 'positive'
  • 6. 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!
  • 7. S.Ducasse 7 Booleans & | not or: and: (lazy) xor: ifTrue:ifFalse: ifFalse:ifTrue: ...
  • 8. S.Ducasse 8 Lazy Logical Operators false and: [1 error: 'crazy'] PrIt-> false and not an error
  • 9. S.Ducasse 9 Yes! ifTrue:ifFalse: is a message send to a Boolean. But optimized by the compiler :)
  • 10. 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
  • 12. 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 ]
  • 13. S.Ducasse 13 Boolean Objects false and true are objects described by classes Boolean,True and False
  • 14. S.Ducasse 14 Let’s the receiver decide!
  • 15. 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
  • 16. 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
  • 17. S.Ducasse 17 | (Or) • true | true -> true • true | false -> true • true | anything -> true • false | true -> true • false | false -> false • false | anything -> anything
  • 18. 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
  • 19. 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
  • 20. 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
  • 22. 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.
  • 24. S.Ducasse 24 Ok so what? You will probably not implement another Boolean classes So is it really that totally useless?
  • 25. S.Ducasse 25 Ternary logic Boolean: true, false, unknown
  • 26. S.Ducasse 26 More important... Message sends act as case statements
  • 27. S.Ducasse 27 OOP: the art of dispatching Subclasses create your vocabulary
  • 28. S.Ducasse 28 Avoid Conditional Use objects and messages VM dispatch is a conditional switch: Use it! AntiIfCampaign
  • 29. S.Ducasse 29 Summary Messages act as a dispatcher Avoid conditional