Find and fix common mistakes faster
DiceHandle >> + aDiceHandle
| res |
res := DiceHandle new
self dices do: [ :each | ... ].
DiceHandle >> + aDiceHandle
| res |
res := DiceHandle new.
self dices do: [ :each | ... ].
.
)x includes: 33
ifTrue: [ self do something ]
Error: Message includes:ifTrue:
does not exist
self assert: players includes: aPlayer
Error: Message assert:includes:
does not exist
Solution
self assert: (players includes: aPlayer)
numbers := OrderedCollection new
add: 35
Error: numbers
is the number 35 and not a collection
Dice >> setFaces: aNumber
^ faces := aNumber
Dice class >> new
^ super new setFaces: 6
Error: Dice new
returns 6 instead of a dice
numbers := OrderedCollection new
add: 35;
yourself
is equivalent to
| numbers |
numbers := OrderedCollection new.
numbers add: 35.
numbers
Solutions
numbers := OrderedCollection new
add: 35;
yourself
Dice class >> new
^ super new setFaces: 6; yourself
add:
and setFaces:
return their argument, not the receiveryourself
after a sequence of messages if you want the receiverBook>>borrow
inLibrary ifFalse: [ ... ].
...
Error: nil
does not understand ifFalse:
Book>>initialize
inLibrary := True
Book>>borrow
inLibrary ifFalse: [ ... ].
...
Error: Class True
does not understand ifFalse:
Solution
Book>>initialize
inLibrary := true
nil
is the unique instance of the class UndefinedObject
true
is the unique instance of the class True
Dice >> roll
faces atRandom
Error: aDice roll
returns aDice
instead of a number
Dice >> roll
faces atRandom
is equivalent to
Dice >> roll
faces atRandom.
^ self
Dice class >> new
super new
setFaces: 0;
yourself
Error: Dice new
returns the class instead of the new instance
Dice class >> new
super new
setFaces: 0;
yourself
is equivalent to
Dice class >> new
super new
setFaces: 0;
yourself.
^ self
new
is sent to a classself
is the class Dice
Dice
and not its newly created instanceSolutions
Dice >> roll
^ faces atRandom
Dice class >> new
^ super new
setFaces: 0;
yourself
self
is returned by default^
to return something elseDice class >> new
^ self new
setFaces: 0;
yourself
Error: System is frozen
Solution
Dice class >> new
^ super new
setFaces: 0;
yourself
super
in overridden methods.
(
and )
^
yourself
/