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;
yourselfis equivalent to
| numbers |
numbers := OrderedCollection new.
numbers add: 35.
numbersSolutions
numbers := OrderedCollection new
add: 35;
yourselfDice class >> new
^ super new setFaces: 6; yourselfadd: 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 := truenil is the unique instance of the class UndefinedObjecttrue is the unique instance of the class TrueDice >> roll
faces atRandom
Error: aDice roll returns aDice instead of a number
Dice >> roll
faces atRandomis equivalent to
Dice >> roll
faces atRandom.
^ selfDice 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;
yourselfis equivalent to
Dice class >> new
super new
setFaces: 0;
yourself.
^ selfnew is sent to a classself is the class DiceDice and not its newly created instanceSolutions
Dice >> roll
^ faces atRandom
Dice class >> new
^ super new
setFaces: 0;
yourselfself is returned by default^ to return something elseDice class >> new
^ self new
setFaces: 0;
yourselfError: System is frozen
Solution
Dice class >> new
^ super new
setFaces: 0;
yourselfsuper in overridden methods.( and )^yourself/