Re: [Pharo-users] how to write this without a if then

2018-11-28 Thread Roelof Wobben
Thanks for all the explanations. and yes, I have to get a feel when I need a new class and when not. and when it's "allowed" to use a if then and when not. and if I understand the explanations I did not ask a class something so a if then is

Re: [Pharo-users] how to write this without a if then

2018-11-28 Thread Richard O'Keefe
DRAT! What (genius negated) designed gmail's interface? If I am wrong that the canHandleInput: class method of IllegalMoveSanta should return false, not true (because the order of the elements of #subclasses is not defined, so that IllegalMoveSanta might *always* be selected), then that is

Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Richard O'Keefe
In Advent-of-Code 2015, the first problem is really quite simple. There are at least two ways to think about it. "CS101": set a counter to 0 for each character of the string if it is '(' increment the counter if it is ')' decrement the counter report the counter "Higher

Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Tim Mackinnon
> The idea of a flat ban on #ifTrue:ifFalse: is ridiculous. > Number>>abs >^self negative ifTrue: [self negated] ifFalse: [self] > > Is there any better way to do this? Not really, you can > only move the #ifTrue:ifFalse: somewhere else. But still it’s always a good thought experiment to

Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Sven Van Caekenberghe
> On 28 Nov 2018, at 06:15, Richard O'Keefe wrote: > > The idea of a flat ban on #ifTrue:ifFalse: is ridiculous. > Number>>abs >^self negative ifTrue: [self negated] ifFalse: [self] > > Is there any better way to do this? Not really, you can > only move the #ifTrue:ifFalse: somewhere

Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Richard O'Keefe
The idea of a flat ban on #ifTrue:ifFalse: is ridiculous. Number>>abs ^self negative ifTrue: [self negated] ifFalse: [self] Is there any better way to do this? Not really, you can only move the #ifTrue:ifFalse: somewhere else. The main argument against #ifTrue:ifFalse: is NOT TO USE IT FOR

Re: [Pharo-users] how to write this without a if then

2018-11-27 Thread Dale Henrichs
Roelof, One technique to eliminating the use of #ifTrue:ifFalse: is to use double dispatching. There are some good examples of using double dispatching in Ralph Johnson's paper "ARITHMETIC AND DOUBLE DISPATCHING IN SMALLTALK-80"[1].  you should be able to get the basic idea by skimming the

[Pharo-users] how to write this without a if then

2018-11-27 Thread Roelof Wobben
Hello, Yesterday I had a talk with luc frabresse about using if then. He said if I understand it right, Its the best to not using a if then or a ifTrue/ifFalse. Can anyone help me figure out how to rewrite this project so I will not use the ifTrue in the basement function. my code so far