SlideShare a Scribd company logo
1 of 16
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/
Common Mistakes and
Debugging in VW
S.Ducasse 2
• Preventing: Most Common Mistakes
• Curing: Debugging Fast (from ST Report July 93)
• Extras
Roadmap
S.Ducasse 3
• true is the boolean value, True its class.
• Book>>initialize
• inLibrary := True
• Book>>initialize
• inLibrary := true
• nil is not an acceptable receiver for ifTrue:
Common Beginner Bugs (I)
S.Ducasse 4
• whileTrue: and whileTrue receivers must be a block
•
[x<y] whileTrue: [x := x + 3]
• Redefining a class:
• Before creating a class, check if it already exists.This is
(sigh) a weakness of the system
Object subclass: #View (Squeak)
• VisualWorks 7.0 has namespaces so less likely to
redefine a class
Common Beginner Bugs (II)
S.Ducasse 5
• In a method self is returned by default. Do not forget ^
for returning something else.
• Packet>>isAddressedTo: aNode
• ^ self addressee = aNode name
Common Beginner Bugs (III)
S.Ducasse 6
• Do not try to access instance variables to initialize
them in a class method. It is impossible!
• A class method can only access class instance variables
and classVariables.
• -> Define and invoke an initialize method on
instances.
InstanceVariable Access in Class Method
S.Ducasse 7
Example
Packet class>>send: aString to: anAddress
contents := aString.
addressee := anAddress
Instead create an instance and invoke instance methods
Packet class>>send: aString to: anAddress
^ self new
contents: aString;
addressee: anAddress
S.Ducasse 8
• Do not try to assign a value to a method argument.
Arguments are read only
setName: aString
aString := aString, 'Device'.
name := aString
Method Argument Are Read-Only
S.Ducasse 9
self and super are Read-Only
• Do not try to modify self and super
S.Ducasse 10
• Never redefine basic-methods (==, basicNew,
basicNew:, basicAt:, basicAt:Put:...)
• Never redefine class
• Never redefine name on the class side!
basic* Method Redefinition
S.Ducasse 11
The hash and = Pair
• Redefine hash when you redefine = so that if a = b
then a hash = b hash
•
Book>>=aBook
^self title = aBook title & (self author = aBook
author)
Book>>hash
^self title hash bitXor: self author hash
S.Ducasse 12
• add: returns the argument and not the receiver, so use
yourself to get the collection back.
• Do not subclass Collection classes.
Common Beginner Bugs - Collections
S.Ducasse 13
• Never iterate over a collection which the iteration
somehow modifies.
•
timers do: [:aTimer| aTimer isActive
ifFalse: [ timers remove: aTimer]]
• First copy the collection
• timers copy do: [:aTimer| aTimer isActive
• ifFalse: [ timers remove:
aTimer]
• Take care, since the iteration can involve various
methods and modifications which may not be obvious!
Don’t iterate over collection and modify it
S.Ducasse 14
• Basic Printing
• Transcript cr; show:‘The total= ’, self total printString.
• Use a global or a class to control printing information
Debug
ifTrue:[Transcript show: self total printString]
Debug > 4
ifTrue:[Transcript show: self total printString]
Debug print:[Transcript show: self total printString]
Debugging - Hints
S.Ducasse 15
• Breakpoints
• self halt.
• self error:‘ invalid’
• Conditional halt
i > 10 ifTrue:[self halt]
i haltIfNil
• In Squeak 3.8: haltIf
•self haltIf: (i > 10)
•i haltIf: [:o | o >10]
•self haltIf: #doIt
BreakPoints
S.Ducasse 16

More Related Content

Viewers also liked (20)

Stoop 413-abstract classes
Stoop 413-abstract classesStoop 413-abstract classes
Stoop 413-abstract classes
 
Stoop sed-smells
Stoop sed-smellsStoop sed-smells
Stoop sed-smells
 
06 debugging
06 debugging06 debugging
06 debugging
 
Stoop 421-design heuristics
Stoop 421-design heuristicsStoop 421-design heuristics
Stoop 421-design heuristics
 
Stoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvwStoop 301-internal objectstructureinvw
Stoop 301-internal objectstructureinvw
 
Stoop 437-proxy
Stoop 437-proxyStoop 437-proxy
Stoop 437-proxy
 
Stoop 423-smalltalk idioms
Stoop 423-smalltalk idiomsStoop 423-smalltalk idioms
Stoop 423-smalltalk idioms
 
8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model8 - OOP - Smalltalk Model
8 - OOP - Smalltalk Model
 
15 - Streams
15 - Streams15 - Streams
15 - Streams
 
Stoop 433-chain
Stoop 433-chainStoop 433-chain
Stoop 433-chain
 
Stoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesignStoop 414-smalltalk elementsofdesign
Stoop 414-smalltalk elementsofdesign
 
Stoop 431-visitor
Stoop 431-visitorStoop 431-visitor
Stoop 431-visitor
 
Stoop 300-block optimizationinvw
Stoop 300-block optimizationinvwStoop 300-block optimizationinvw
Stoop 300-block optimizationinvw
 
Stoop 416-lsp
Stoop 416-lspStoop 416-lsp
Stoop 416-lsp
 
11 bytecode
11 bytecode11 bytecode
11 bytecode
 
Stoop ed-class forreuse
Stoop ed-class forreuseStoop ed-class forreuse
Stoop ed-class forreuse
 
9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)9 - OOP - Smalltalk Classes (b)
9 - OOP - Smalltalk Classes (b)
 
Stoop 400-metaclass only
Stoop 400-metaclass onlyStoop 400-metaclass only
Stoop 400-metaclass only
 
01 intro
01 intro01 intro
01 intro
 
Stoop ed-subtyping subclassing
Stoop ed-subtyping subclassingStoop ed-subtyping subclassing
Stoop ed-subtyping subclassing
 

Similar to Debugging VisualWorks (20)

10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)10 - OOP - Inheritance (a)
10 - OOP - Inheritance (a)
 
Stoop ed-frameworks
Stoop ed-frameworksStoop ed-frameworks
Stoop ed-frameworks
 
10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)10 - OOP - Inheritance (b)
10 - OOP - Inheritance (b)
 
Stoop 450-s unit
Stoop 450-s unitStoop 450-s unit
Stoop 450-s unit
 
Stoop ed-lod
Stoop ed-lodStoop ed-lod
Stoop ed-lod
 
Stoop ed-some principles
Stoop ed-some principlesStoop ed-some principles
Stoop ed-some principles
 
Stoop 432-singleton
Stoop 432-singletonStoop 432-singleton
Stoop 432-singleton
 
Stoop 303-advanced blocks
Stoop 303-advanced blocksStoop 303-advanced blocks
Stoop 303-advanced blocks
 
9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)9 - OOP - Smalltalk Classes (a)
9 - OOP - Smalltalk Classes (a)
 
2 - OOP
2 - OOP2 - OOP
2 - OOP
 
Ruby :: Training 1
Ruby :: Training 1Ruby :: Training 1
Ruby :: Training 1
 
8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages8 - OOP - Syntax & Messages
8 - OOP - Syntax & Messages
 
Java assgnmt2.
Java assgnmt2.Java assgnmt2.
Java assgnmt2.
 
Stoop ed-unit ofreuse
Stoop ed-unit ofreuseStoop ed-unit ofreuse
Stoop ed-unit ofreuse
 
Stoop 304-metaclasses
Stoop 304-metaclassesStoop 304-metaclasses
Stoop 304-metaclasses
 
SUnit: latest developments
SUnit: latest developmentsSUnit: latest developments
SUnit: latest developments
 
Drush. Why should it be used?
Drush. Why should it be used?Drush. Why should it be used?
Drush. Why should it be used?
 
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
Sergei Stryukov.Drush.Why it should be used.DrupalCamp Kyiv 2011
 
Stoop 423-some designpatterns
Stoop 423-some designpatternsStoop 423-some designpatterns
Stoop 423-some designpatterns
 
Python.ppt
Python.pptPython.ppt
Python.ppt
 

More from The World of Smalltalk (16)

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
 
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
 
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-dual interface
Stoop ed-dual interfaceStoop ed-dual interface
Stoop ed-dual interface
 
Stoop 440-adaptor
Stoop 440-adaptorStoop 440-adaptor
Stoop 440-adaptor
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

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
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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_...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.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
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 

Debugging VisualWorks

  • 1. 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/ Common Mistakes and Debugging in VW
  • 2. S.Ducasse 2 • Preventing: Most Common Mistakes • Curing: Debugging Fast (from ST Report July 93) • Extras Roadmap
  • 3. S.Ducasse 3 • true is the boolean value, True its class. • Book>>initialize • inLibrary := True • Book>>initialize • inLibrary := true • nil is not an acceptable receiver for ifTrue: Common Beginner Bugs (I)
  • 4. S.Ducasse 4 • whileTrue: and whileTrue receivers must be a block • [x<y] whileTrue: [x := x + 3] • Redefining a class: • Before creating a class, check if it already exists.This is (sigh) a weakness of the system Object subclass: #View (Squeak) • VisualWorks 7.0 has namespaces so less likely to redefine a class Common Beginner Bugs (II)
  • 5. S.Ducasse 5 • In a method self is returned by default. Do not forget ^ for returning something else. • Packet>>isAddressedTo: aNode • ^ self addressee = aNode name Common Beginner Bugs (III)
  • 6. S.Ducasse 6 • Do not try to access instance variables to initialize them in a class method. It is impossible! • A class method can only access class instance variables and classVariables. • -> Define and invoke an initialize method on instances. InstanceVariable Access in Class Method
  • 7. S.Ducasse 7 Example Packet class>>send: aString to: anAddress contents := aString. addressee := anAddress Instead create an instance and invoke instance methods Packet class>>send: aString to: anAddress ^ self new contents: aString; addressee: anAddress
  • 8. S.Ducasse 8 • Do not try to assign a value to a method argument. Arguments are read only setName: aString aString := aString, 'Device'. name := aString Method Argument Are Read-Only
  • 9. S.Ducasse 9 self and super are Read-Only • Do not try to modify self and super
  • 10. S.Ducasse 10 • Never redefine basic-methods (==, basicNew, basicNew:, basicAt:, basicAt:Put:...) • Never redefine class • Never redefine name on the class side! basic* Method Redefinition
  • 11. S.Ducasse 11 The hash and = Pair • Redefine hash when you redefine = so that if a = b then a hash = b hash • Book>>=aBook ^self title = aBook title & (self author = aBook author) Book>>hash ^self title hash bitXor: self author hash
  • 12. S.Ducasse 12 • add: returns the argument and not the receiver, so use yourself to get the collection back. • Do not subclass Collection classes. Common Beginner Bugs - Collections
  • 13. S.Ducasse 13 • Never iterate over a collection which the iteration somehow modifies. • timers do: [:aTimer| aTimer isActive ifFalse: [ timers remove: aTimer]] • First copy the collection • timers copy do: [:aTimer| aTimer isActive • ifFalse: [ timers remove: aTimer] • Take care, since the iteration can involve various methods and modifications which may not be obvious! Don’t iterate over collection and modify it
  • 14. S.Ducasse 14 • Basic Printing • Transcript cr; show:‘The total= ’, self total printString. • Use a global or a class to control printing information Debug ifTrue:[Transcript show: self total printString] Debug > 4 ifTrue:[Transcript show: self total printString] Debug print:[Transcript show: self total printString] Debugging - Hints
  • 15. S.Ducasse 15 • Breakpoints • self halt. • self error:‘ invalid’ • Conditional halt i > 10 ifTrue:[self halt] i haltIfNil • In Squeak 3.8: haltIf •self haltIf: (i > 10) •i haltIf: [:o | o >10] •self haltIf: #doIt BreakPoints