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

Igor Stasenko siguctua at gmail.com
Sun Feb 13 00:44:17 CET 2011

On 13 February 2011 00:17, Levente Uzonyi <leves at elte.hu> wrote:
> 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:?

Don't try to convince me that there are sort of problems which can be
solved only by using case statement :)
First, get rid of these integers in your code. Use symbolic names.
And then for dispatching using parameter, there is a #peform: primitive.

So, then switch statement will be turned into:

self peform: (self decode: someInteger)

and this is how it should look like.
And again, if you can avoid using integers at all, use symbols , so
you don't have to decode/translate them.
Just do #perform.

I thought that this is obvious for you.

> Levente

Best regards,
Igor Stasenko AKA sig.

More information about the Pharo-project mailing list