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

Levente Uzonyi leves at elte.hu
Sun Feb 13 00:59:24 CET 2011

On Sun, 13 Feb 2011, Igor Stasenko wrote:

> Don't try to convince me that there are sort of problems which can be
> solved only by using case statement :)

We all know that it can be solved, but the solution won't be nicer at all, 
instead it will be a lot slower.

> First, get rid of these integers in your code. Use symbolic names.
> And then for dispatching using parameter, there is a #peform: primitive.

The integers are from a binary stream, so I can't do much about it.

> 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.

What you wrote here is obvious, but not an answer to my question. What 
should #decode: do? Use #detect:? Or a dictionary? Maybe a binary search 
on an array? Or should it be a bunch of #ifTrue:ifFalse: conditionals? (I 
guess the separate class per integer idea is abandoned, but who knows.)

Also note that #perform:with: is ~11x slower on Cog than sending a 
message. And a send is a lot slower (~5.5x IIRC) than a direct assignment. 
That's ~55x combined slowdown not counting the integer->selector matching.


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

More information about the Pharo-project mailing list