SlideShare une entreprise Scribd logo
1  sur  29
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

Contenu connexe

Plus de The World of Smalltalk (20)

09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
04 idioms
04 idioms04 idioms
04 idioms
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
02 basics
02 basics02 basics
02 basics
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
Stoop sed-sharing ornot
Stoop sed-sharing ornotStoop sed-sharing ornot
Stoop sed-sharing ornot
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop sed-class initialization
Stoop sed-class initializationStoop sed-class initialization
Stoop sed-class initialization
 
Stoop metaclasses
Stoop metaclassesStoop metaclasses
Stoop metaclasses
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-inheritance composition
Stoop ed-inheritance compositionStoop ed-inheritance composition
Stoop ed-inheritance composition
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 

Dernier

NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 

Dernier (20)

NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 

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