S.Ducasse Stéphane Ducasse 1 Common Mistakes and Debugging in VW.

Slides:



Advertisements
Similar presentations
From Objects to Actors Study of a Limited Symbiosis in Smalltalk-80.
Advertisements

Overview of Previous Lesson(s) Over View  Assertions  assert() library function is declared in the cassert header to check logical conditions in native.
11. A bit of Smalltalk. © O. Nierstrasz P2 — A bit of Smalltalk 11.2 A bit of Smalltalk Overview  Some history  Smalltalk syntax & object model  The.
Stéphane Ducasse«ChapterNr».1 Selected Design Patterns Design Patterns are recurrent solutions to design problems They are pros and cons We already saw:
Principles of Object-Oriented Software Development The language Smalltalk.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Stéphane Ducasse«ChapterNr».1 Abstract Classes Should not be instantiated (abstract in Java) But can defined complete methods Defines a protocol common.
Access to Names Namespaces, Scopes, Access privileges.
Stéphane Ducasse9.1 Inheritance Semantics and Lookup.
Stéphane Ducasse8.1 Syntax and Messages The syntax of Smalltalk is simple and uniform, but it can look strange at first sight! Literals: numbers, strings,
6. Debugging. Birds-eye view © Oscar Nierstrasz ST — Introduction 1.2 It can be easier to talk to objects than to read classes — The system is alive.
Stéphane Ducasse 1 The Taste of Smalltalk.
13. A bit of Smalltalk. © Oscar Nierstrasz 2 Roadmap  The origins of Smalltalk  What is Smalltalk?  Syntax in a nutshell  Seaside — web development.
2. Smalltalk Basics. © Oscar Nierstrasz ST — Smalltalk Basics 2.2 Roadmap  Everything is an Object  Syntax on a Postcard  Three Kinds of Messages 
Some Basic Points on Classes
S.Ducasse Stéphane Ducasse 1 A Taste of Smalltalk.
Stéphane Ducasse 1 Syntax and Messages.
6. Debugging. © Oscar Nierstrasz ST — Debugging 6.2 Roadmap  Common syntactic errors  Common semantic errors  Encapsulation errors  Class/instance.
6. Debugging. © Oscar Nierstrasz ST — Debugging 6.2 Roadmap  Common syntactic errors  Common semantic errors  Encapsulation errors  Class/instance.
Stéphane Ducasse 1 Objects to the Roots: Learning from beauty.
28-Jun-15 Access to Names Namespaces, Scopes, Access privileges.
03G-1 Everything is an Object Examining builtin classes All these are classes in Little Smalltalk:  Object  Class  Method  Block  Boolean True False.
Squeak Collections The Squeak collection hierarchy. Some collection operators. Working with collections. For-loops.
1 Advanced Material The following slides contain advanced material and are optional.
C Slides and captured lecture (video and sound) are available at:
Object-oriented programming and design 1 Smalltalk in a Nutshell Objects & classes Messages & methods Inheritance & metaclasses.
Stéphane Ducasse5.1 Smalltalk in a Nutshell OO Model in a Nutshell Syntax in a Nutshell.
Stéphane Ducasse 1 Smalltalk in a Nutshell.
Stéphane Ducasse4.1 A Taste of Smalltalk Two examples: –‘hello world’ –A Tomagoshi To give you an idea of: –the syntax –the elementary objects and classes.
Stéphane Ducasse«ChapterNr».1 Basic Objects, Conditionals and Loops Booleans Basic Loops Overview of the Collection hierarchy— more than 80 classes: (Bag,
S.Ducasse Stéphane Ducasse 1 The Taste of Smalltalk.
The Ruby Programming Language
CSE 486/586 CSE 486/586 Distributed Systems PA Best Practices Steve Ko Computer Sciences and Engineering University at Buffalo.
S.Ducasse Stéphane Ducasse 1 Smalltalk Coding Idioms.
1-1 Generic Types in Java Format for a generic (parameterized) type and instantiation of a generic type.
S.Ducasse Stéphane Ducasse 1 Processes and Concurrency in VW.
S.Ducasse Stéphane Ducasse 1 Classes and Metaclasses - an Analysis.
Chapter 9: MuPAD Programming II Procedures MATLAB for Scientist and Engineers Using Symbolic Toolbox.
Centralized vs. Decentralized Interpreter Pattern Visitor Pattern.
Smalltalk (and Squeak) Aida Dungan and Rick Shreve.
Linear Equations in Two Variables A Linear Equation in Two Variables is any equation that can be written in the form where A and B are not both zero.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Inheritance Semantics and Method Lookup.
Object-oriented programming and design 1 Object Identity = vs. == copying objects Value Object ValueWithHistory.
Stéphane Ducasse 1 Elements of Design - Inheritance/Compositio n.
Stéphane Ducasse 1 Singleton.
Stéphane Ducasse 1 Some Advanced Points on Classes.
Stéphane Ducasse7.1 Let’s Play Objects Simulate a LAN physically Set up a context for –future chapters –Exercises Some forward references to intriguate.
Sets Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg.
Stéphane Ducasse 1 Some Points on Classes.
S.Ducasse Stéphane Ducasse 1 Smalltalk in a Nutshell.
S.Ducasse Stéphane Ducasse savoie.fr e/ e/ 1 Smalltalk in a Nutshell.
CSE 3302 Programming Languages Chengkai Li Fall 2007 Smalltalk Lecture 14 – Smalltalk, Fall CSE3302 Programming Languages, UT-Arlington ©Chengkai.
Stéphane Ducasse 1 A Little Journey in the Smalltalk Syntax.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Stéphane Ducasse 1 Elements of Design - Unit of Reuse.
Stéphane Ducasse 1 Abstract Classes.
S.Ducasse Stéphane Ducasse 1 Some Advanced Points on Classes.
S.Ducasse 1 Instance Initialization How to ensure that an instance is well initialized? Automatic initialize Lazy initialization Proposing the right interface.
Design Points - Law of Demeter
COMP280:Introduction to Software Development Week 12, Lecture 34
Feedback from Assignment 1
slides created by Ethan Apter
Intro to Computer Science CS1510 Dr. Sarah Diesburg
slides created by Ethan Apter
CS 331 Principles of Programming Languages
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Nate Brunelle Today: Functions again, Scope
CSE 3302 Programming Languages
Smalltalk on a Dime.
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Presentation transcript:

S.Ducasse Stéphane Ducasse 1 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. Instance Variable 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