SlideShare a Scribd company logo
Stéphane Ducasse 1
Stéphane Ducasse
stephane.ducasse@inria.fr
http://stephane.ducasse.free.fr/
The Taste of Smalltalk
S.Ducasse 2
Goals
Two examples:
“hello world”
a LAN simulator
To give you an idea of:
the syntax
the elementary objects and classes
the environment
To provide the basis for all the lectures:
all the code examples,
constructs,
design decisions, ...
S.Ducasse 3
An Advice
You do not have to know everything!!!
“Try not to care - Beginning Smalltalk programmers often
have trouble because they think they need to understand all
the details of how a thing works before they can use it.This
means it takes quite a while before they can master
Transcript show:‘Hello World’. One of the great leaps in OO
is to be able to answer the question "How does this work?"
with "I don’t care"“.Alan Knight. Smalltalk Guru
We will show you how to learn and find your way
S.Ducasse 4
Some Conventions
ReturnValues
1 + 3 -> 4
Node new -> aNode
Method selector #add:
Instance Method defined in class Node:
Node>>accept: aPacket
Class method defined in class Node (in the class of
the class Node)
Node class>>withName: aSymbol
aSomething is an instance of the class Something
S.Ducasse 5
Roadmap
“hello world”
a LAN simulator
S.Ducasse 6
Hello World
Transcript show:‘hello world’
At anytime we can dynamically ask the system to evaluate
an expression.To evaluate an expression, select it and with
the middle mouse button apply doIt.
Transcript is a special object that is a kind of standard
output.
It refers to a TextCollector instance associated with the
launcher.
S.Ducasse 7
Transcript show:‘hello world’
S.Ducasse 8
Everything is an Object
The workspace is an object.
The window is an object: it is an instance of ApplicationWindow.
The text editor is an object: it is an instance of ParagraphEditor.
The scrollbars are objects too.
‘hello word’ is an object: it is aString instance of String.
#show: is a Symbol that is also an object.
The mouse is an object.
The parser is an object: instance of Parser.
The compiler is also an object: instance of Compiler.
The process scheduler is also an object.
The garbage collector is an object: instance of MemoryObject.
Smalltalk is a consistent, uniform world written in itself.You can learn
how it is implemented, you can extend it or even modify it.All the code
is available and readable
S.Ducasse 9
Smalltalk Object 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 10
Roadmap
Hello World
First look at the syntax
LAN Simulator
S.Ducasse 11
Complete Syntax on a PostCard
exampleWithNumber: x
“Illustrates every part of Smalltalk method syntax. It has unary, binary, and key
word messages, declares arguments and 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.”
|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 12
Yes ifTrue: is sent to a boolean
Weather isRaining
ifTrue: [self takeMyUmbrella]
ifFalse: [self takeMySunglasses]
ifTrue:ifFalse is sent to an object: a boolean!
S.Ducasse 13
Yes a collection is iterating on itself
#(1 2 -4 -86)
do: [:each | Transcript show: each abs printString.
Transcript cr ]
> 1
> 2
> 4
> 86
Yes we ask the collection object to perform the
loop on itself
S.Ducasse 14
DoIt, PrintIt, InspectIt and Accept
Accept = Compile: Accept a method or a class
definition
DoIt: send a message to an object
PrintIt: send a message to an object + print the
result (#printOn:)
InspectIt: send a message to an object + inspect
the result (#inspect)
S.Ducasse 15
Objects send messages
Transcript show:‘hello world’
The above expression is a message
the object Transcript is the receiver of the message
the selector of the message is #show:
one argument: a string ‘hello world’
Transcript is a global variable (starts with an uppercase
letter) that refers to the Launcher’s report part.
S.Ducasse 16
Vocabulary Point
Message passing or sending a message is equivalent to
invoking a method in Java or C++
calling a procedure in procedural languages
applying a function in functional languages
of course the last two points must be considered under the
light of polymorphism
S.Ducasse 17
Roadmap
Hello World
First look at the syntax
LAN Simulator
S.Ducasse 18
A LAN Simulator
A LAN contains nodes, workstations, printers, file
servers. Packets are sent in a LAN and each node
treats them differently.
mac
node3
node2
pcnode1
lpr
S.Ducasse 19
Three Kinds of Objects
Node and its subclasses represent the entities that
are connected to form a LAN.
Packet represents the information that flows
between Nodes.
NetworkManager manages how the nodes are
connected
S.Ducasse 20
LAN Design
Node
WorkstationPrinter
NetworkManager
Packet
addressee
contents
originator
isSentBy: aNode
isAddressedTo: aNode
name
accept: aPacket
send: aPacket
hasNextNode
originate: aPacket
accept: aPacket
print: aPacket
accept: aPacket
declareNode: aNode
undeclareNode: aNode
connectNodes: anArrayOfAddressees nextNode
S.Ducasse 21
Interactions Between Nodes
accept: aPacket
send: aPacket
nodePrinter aPacket node1
isAddressedTo: nodePrinter
accept: aPacket
print: aPacket
[true]
[false]
S.Ducasse 22
Node and Packet Creation
|macNode pcNode node1 printerNode node2 node3 packet|
macNode := Workstation withName: #mac.
pcNode := Workstation withName: #pc.
node1 := Node withName: #node1.
node2 := Node withName: #node2.
node3 := Node withName: #node2.
printerNode := Printer withName: #lpr.
macNode nextNode: node1.
node1 nextNode: pcNode.
pcNode nextNode: node2.
node3 nextNode: printerNode.
lpr nextNode: macNode.
packet := Packet send: 'This packet travelled to' to: #lpr.
S.Ducasse 23
Objects Send Messages
Message: 1 + 2
receiver : 1 (an instance of SmallInteger)
selector: #+
arguments: 2
Message: lpr nextNode: macNode
receiver: lpr (an instance of LanPrinter)
selector: #nextNode:
arguments: macNode (an instance of Workstation)
Message: Packet send: 'This packet travelled to' to: #lpr
receiver: Packet (a class)
selector: #send:to:
arguments: 'This packet travelled to' and #lpr
S.Ducasse 24
Transmitting a Packet
| aLan packet macNode|
...
macNode := aLan findNodeWithAddress: #mac.
packet := Packet send: 'This packet travelled to the printer'
to: #lpr.
macNode originate: packet.
-> mac sends a packet to pc
-> pc sends a packet to node1
-> node1 sends a packet to node2
-> node2 sends a packet to node3
-> node3 sends a packet to lpr
-> lpr is printing
-> this packet travelled to lpr
S.Ducasse 25
How to Define a Class?
• Fill the template:
NameOfSuperclass subclass: #NameOfClass
instanceVariableNames: 'instVarName1'
classVariableNames: 'ClassVarName1 ClassVarName2'
poolDictionaries: ''
category: 'LAN'
S.Ducasse 26
Packet
• For example to create the class Packet
Object subclass: #Packet
instanceVariableNames: 'addressee originator
contents '
classVariableNames: ''
poolDictionaries: ''
category: 'LAN'
S.Ducasse 27
How to Define a Method?
message selector and argument names
"comment stating purpose of message"
| temporary variable names |
statements
accept: thePacket
"If the packet is addressed to me, print it. Otherwise just
behave like a normal node."
(thePacket isAddressedTo: self)
ifTrue: [self print: thePacket]
ifFalse: [super accept: thePacket]
S.Ducasse 28
In Java
• In Java we would write
void accept(thePacket Packet)
/*If the packet is addressed to me, print it. Otherwise just
behave like a normal node.*/
if (thePacket.isAddressedTo(this)){
this.print(thePacket)}
else super.accept(thePacket)}
S.Ducasse 29
Summary
What is a message?
What is the message receiver?
What is the method selector?
How to create a class?
How to define a method?

More Related Content

What's hot

Pharo - I have a dream @ Smalltalks Conference 2009
Pharo -  I have a dream @ Smalltalks Conference 2009Pharo -  I have a dream @ Smalltalks Conference 2009
Pharo - I have a dream @ Smalltalks Conference 2009
Pharo
 
2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut
Pharo
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)The World of Smalltalk
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
CHOOSE
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationJonathan Wage
 
Pharo Hands-on: 05 object model
Pharo Hands-on: 05 object modelPharo Hands-on: 05 object model
Pharo Hands-on: 05 object model
Pharo
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntax
Pharo
 

What's hot (20)

Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)9 - OOP - Smalltalk Classes (c)
9 - OOP - Smalltalk Classes (c)
 
5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)5 - OOP - Smalltalk in a Nutshell (a)
5 - OOP - Smalltalk in a Nutshell (a)
 
5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)5 - OOP - Smalltalk in a Nutshell (c)
5 - OOP - Smalltalk in a Nutshell (c)
 
5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)5 - OOP - Smalltalk in a Nutshell (b)
5 - OOP - Smalltalk in a Nutshell (b)
 
02 basics
02 basics02 basics
02 basics
 
Pharo - I have a dream @ Smalltalks Conference 2009
Pharo -  I have a dream @ Smalltalks Conference 2009Pharo -  I have a dream @ Smalltalks Conference 2009
Pharo - I have a dream @ Smalltalks Conference 2009
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
04 idioms
04 idioms04 idioms
04 idioms
 
12 virtualmachine
12 virtualmachine12 virtualmachine
12 virtualmachine
 
07 bestpractice
07 bestpractice07 bestpractice
07 bestpractice
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
03 standardclasses
03 standardclasses03 standardclasses
03 standardclasses
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut2013 lecture-02-syntax shortnewcut
2013 lecture-02-syntax shortnewcut
 
4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)4 - OOP - Taste of Smalltalk (VisualWorks)
4 - OOP - Taste of Smalltalk (VisualWorks)
 
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in SmalltalkChoose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
Choose'10: Stephane Ducasse - Powerful DSL engineering in Smalltalk
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Pharo Hands-on: 05 object model
Pharo Hands-on: 05 object modelPharo Hands-on: 05 object model
Pharo Hands-on: 05 object model
 
Pharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntaxPharo Hands-On: 02 syntax
Pharo Hands-On: 02 syntax
 

Similar to 4 - OOP - Taste of Smalltalk (Squeak)

TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
Max Kleiner
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsJames Dennis
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
Robbert
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
kishore1986
 
Arduino Teaching Program
Arduino Teaching ProgramArduino Teaching Program
Arduino Teaching Program
Max Kleiner
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
SharanShrinivasan1
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
rowiebornia
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
DavidMaina47
 
Introduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkiiIntroduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkii
cmdept1
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
Jayaprasanna4
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
chanchal214
 
node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the futureJeff Miccolis
 
Howto curses
Howto cursesHowto curses
Howto curses
Sergi Duró
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
Katy Allen
 

Similar to 4 - OOP - Taste of Smalltalk (Squeak) (20)

6 - OOP - LAN Example
6 - OOP - LAN Example6 - OOP - LAN Example
6 - OOP - LAN Example
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
ZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 LabsZeroMQ: Super Sockets - by J2 Labs
ZeroMQ: Super Sockets - by J2 Labs
 
Stoop 305-reflective programming5
Stoop 305-reflective programming5Stoop 305-reflective programming5
Stoop 305-reflective programming5
 
Ruby Meets Cocoa
Ruby Meets CocoaRuby Meets Cocoa
Ruby Meets Cocoa
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Arduino Teaching Program
Arduino Teaching ProgramArduino Teaching Program
Arduino Teaching Program
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction to-linux
Introduction to-linuxIntroduction to-linux
Introduction to-linux
 
Introduction-to-Linux.pptx
Introduction-to-Linux.pptxIntroduction-to-Linux.pptx
Introduction-to-Linux.pptx
 
Introduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkiiIntroduction khgjkhygkjiyhgikjyhgikygkii
Introduction khgjkhygkjiyhgikjyhgikygkii
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
study-of-network-simulator.pdf
study-of-network-simulator.pdfstudy-of-network-simulator.pdf
study-of-network-simulator.pdf
 
Working with NS2
Working with NS2Working with NS2
Working with NS2
 
Extending ns
Extending nsExtending ns
Extending ns
 
2 - OOP
2 - OOP2 - OOP
2 - OOP
 
node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the future
 
Howto curses
Howto cursesHowto curses
Howto curses
 
Designing A Project Using Java Programming
Designing A Project Using Java ProgrammingDesigning A Project Using Java Programming
Designing A Project Using Java Programming
 

More from The World of Smalltalk (20)

05 seaside canvas
05 seaside canvas05 seaside canvas
05 seaside canvas
 
99 questions
99 questions99 questions
99 questions
 
13 traits
13 traits13 traits
13 traits
 
10 reflection
10 reflection10 reflection
10 reflection
 
09 metaclasses
09 metaclasses09 metaclasses
09 metaclasses
 
08 refactoring
08 refactoring08 refactoring
08 refactoring
 
06 debugging
06 debugging06 debugging
06 debugging
 
05 seaside
05 seaside05 seaside
05 seaside
 
01 intro
01 intro01 intro
01 intro
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
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-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
 
Stoop ed-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 

Recently uploaded

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
ShivajiThube2
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
kimdan468
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
JEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questionsJEE1_This_section_contains_FOUR_ questions
JEE1_This_section_contains_FOUR_ questions
 
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBCSTRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
STRAND 3 HYGIENIC PRACTICES.pptx GRADE 7 CBC
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

4 - OOP - Taste of Smalltalk (Squeak)

  • 1. Stéphane Ducasse 1 Stéphane Ducasse stephane.ducasse@inria.fr http://stephane.ducasse.free.fr/ The Taste of Smalltalk
  • 2. S.Ducasse 2 Goals Two examples: “hello world” a LAN simulator To give you an idea of: the syntax the elementary objects and classes the environment To provide the basis for all the lectures: all the code examples, constructs, design decisions, ...
  • 3. S.Ducasse 3 An Advice You do not have to know everything!!! “Try not to care - Beginning Smalltalk programmers often have trouble because they think they need to understand all the details of how a thing works before they can use it.This means it takes quite a while before they can master Transcript show:‘Hello World’. One of the great leaps in OO is to be able to answer the question "How does this work?" with "I don’t care"“.Alan Knight. Smalltalk Guru We will show you how to learn and find your way
  • 4. S.Ducasse 4 Some Conventions ReturnValues 1 + 3 -> 4 Node new -> aNode Method selector #add: Instance Method defined in class Node: Node>>accept: aPacket Class method defined in class Node (in the class of the class Node) Node class>>withName: aSymbol aSomething is an instance of the class Something
  • 6. S.Ducasse 6 Hello World Transcript show:‘hello world’ At anytime we can dynamically ask the system to evaluate an expression.To evaluate an expression, select it and with the middle mouse button apply doIt. Transcript is a special object that is a kind of standard output. It refers to a TextCollector instance associated with the launcher.
  • 8. S.Ducasse 8 Everything is an Object The workspace is an object. The window is an object: it is an instance of ApplicationWindow. The text editor is an object: it is an instance of ParagraphEditor. The scrollbars are objects too. ‘hello word’ is an object: it is aString instance of String. #show: is a Symbol that is also an object. The mouse is an object. The parser is an object: instance of Parser. The compiler is also an object: instance of Compiler. The process scheduler is also an object. The garbage collector is an object: instance of MemoryObject. Smalltalk is a consistent, uniform world written in itself.You can learn how it is implemented, you can extend it or even modify it.All the code is available and readable
  • 9. S.Ducasse 9 Smalltalk Object 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
  • 10. S.Ducasse 10 Roadmap Hello World First look at the syntax LAN Simulator
  • 11. S.Ducasse 11 Complete Syntax on a PostCard exampleWithNumber: x “Illustrates every part of Smalltalk method syntax. It has unary, binary, and key word messages, declares arguments and 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.” |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
  • 12. S.Ducasse 12 Yes ifTrue: is sent to a boolean Weather isRaining ifTrue: [self takeMyUmbrella] ifFalse: [self takeMySunglasses] ifTrue:ifFalse is sent to an object: a boolean!
  • 13. S.Ducasse 13 Yes a collection is iterating on itself #(1 2 -4 -86) do: [:each | Transcript show: each abs printString. Transcript cr ] > 1 > 2 > 4 > 86 Yes we ask the collection object to perform the loop on itself
  • 14. S.Ducasse 14 DoIt, PrintIt, InspectIt and Accept Accept = Compile: Accept a method or a class definition DoIt: send a message to an object PrintIt: send a message to an object + print the result (#printOn:) InspectIt: send a message to an object + inspect the result (#inspect)
  • 15. S.Ducasse 15 Objects send messages Transcript show:‘hello world’ The above expression is a message the object Transcript is the receiver of the message the selector of the message is #show: one argument: a string ‘hello world’ Transcript is a global variable (starts with an uppercase letter) that refers to the Launcher’s report part.
  • 16. S.Ducasse 16 Vocabulary Point Message passing or sending a message is equivalent to invoking a method in Java or C++ calling a procedure in procedural languages applying a function in functional languages of course the last two points must be considered under the light of polymorphism
  • 17. S.Ducasse 17 Roadmap Hello World First look at the syntax LAN Simulator
  • 18. S.Ducasse 18 A LAN Simulator A LAN contains nodes, workstations, printers, file servers. Packets are sent in a LAN and each node treats them differently. mac node3 node2 pcnode1 lpr
  • 19. S.Ducasse 19 Three Kinds of Objects Node and its subclasses represent the entities that are connected to form a LAN. Packet represents the information that flows between Nodes. NetworkManager manages how the nodes are connected
  • 20. S.Ducasse 20 LAN Design Node WorkstationPrinter NetworkManager Packet addressee contents originator isSentBy: aNode isAddressedTo: aNode name accept: aPacket send: aPacket hasNextNode originate: aPacket accept: aPacket print: aPacket accept: aPacket declareNode: aNode undeclareNode: aNode connectNodes: anArrayOfAddressees nextNode
  • 21. S.Ducasse 21 Interactions Between Nodes accept: aPacket send: aPacket nodePrinter aPacket node1 isAddressedTo: nodePrinter accept: aPacket print: aPacket [true] [false]
  • 22. S.Ducasse 22 Node and Packet Creation |macNode pcNode node1 printerNode node2 node3 packet| macNode := Workstation withName: #mac. pcNode := Workstation withName: #pc. node1 := Node withName: #node1. node2 := Node withName: #node2. node3 := Node withName: #node2. printerNode := Printer withName: #lpr. macNode nextNode: node1. node1 nextNode: pcNode. pcNode nextNode: node2. node3 nextNode: printerNode. lpr nextNode: macNode. packet := Packet send: 'This packet travelled to' to: #lpr.
  • 23. S.Ducasse 23 Objects Send Messages Message: 1 + 2 receiver : 1 (an instance of SmallInteger) selector: #+ arguments: 2 Message: lpr nextNode: macNode receiver: lpr (an instance of LanPrinter) selector: #nextNode: arguments: macNode (an instance of Workstation) Message: Packet send: 'This packet travelled to' to: #lpr receiver: Packet (a class) selector: #send:to: arguments: 'This packet travelled to' and #lpr
  • 24. S.Ducasse 24 Transmitting a Packet | aLan packet macNode| ... macNode := aLan findNodeWithAddress: #mac. packet := Packet send: 'This packet travelled to the printer' to: #lpr. macNode originate: packet. -> mac sends a packet to pc -> pc sends a packet to node1 -> node1 sends a packet to node2 -> node2 sends a packet to node3 -> node3 sends a packet to lpr -> lpr is printing -> this packet travelled to lpr
  • 25. S.Ducasse 25 How to Define a Class? • Fill the template: NameOfSuperclass subclass: #NameOfClass instanceVariableNames: 'instVarName1' classVariableNames: 'ClassVarName1 ClassVarName2' poolDictionaries: '' category: 'LAN'
  • 26. S.Ducasse 26 Packet • For example to create the class Packet Object subclass: #Packet instanceVariableNames: 'addressee originator contents ' classVariableNames: '' poolDictionaries: '' category: 'LAN'
  • 27. S.Ducasse 27 How to Define a Method? message selector and argument names "comment stating purpose of message" | temporary variable names | statements accept: thePacket "If the packet is addressed to me, print it. Otherwise just behave like a normal node." (thePacket isAddressedTo: self) ifTrue: [self print: thePacket] ifFalse: [super accept: thePacket]
  • 28. S.Ducasse 28 In Java • In Java we would write void accept(thePacket Packet) /*If the packet is addressed to me, print it. Otherwise just behave like a normal node.*/ if (thePacket.isAddressedTo(this)){ this.print(thePacket)} else super.accept(thePacket)}
  • 29. S.Ducasse 29 Summary What is a message? What is the message receiver? What is the method selector? How to create a class? How to define a method?