[Pharo-project] could we agree to remove caseOf: and caseOf:otherwise:

Levente Uzonyi leves at elte.hu
Sun Feb 13 00:17:55 CET 2011


On Sat, 12 Feb 2011, Igor Stasenko wrote:

> oh come on. Switch statement should live where it belongs to: C code.

It's nothing like C's switch statement, and I'm sure you know that.

>
> Why we should support this ridiculous syntax constructs in smalltalk?

What's so ridiculous about it?

> IMO:
> All users of such code should die. And i don't care if they are
> working fast or not..
> This is plainly against the spirit of smalltalk.

Okay, then enlighten me please, how one should rewrite the following 
dispatch without #caseOf:?

You have some integers: 0 83 67 77 68 72 80 112 113 87 70 82. 
When a variable's value is equal to any of these, a predefined value has 
to be set to an instance variable depending on the integer. The current 
code is like:

foo caseOf: {
 	[ 0 ] -> [ var2 := x ].
 	[ 83 ] -> [ var13 := x ].
 	...

Should I use #detect: to find the variable? Or a dictionary? Maybe a 
binary search on an array? Or a bunch of #ifTrue:ifFalse: conditionals? 
Maybe a separate class for each variable and let the VM do the dispatch?
How should I set the value? With #perform:? Or #instVarAt:put:?


Levente

>
>>
>> Levente
>>
>>
>
>
>
> -- 
> Best regards,
> Igor Stasenko AKA sig.
>
>




More information about the Pharo-project mailing list