case/switch statement?
D H
d at e.f
Fri Jun 17 16:02:58 EDT 2005
Peter Hansen wrote:
> D H wrote:
>
>> Peter Hansen wrote:
>>
>>> With a case statement, on the other hand, you *know* that it must be
>>> just simple conditionals (a series of x == some_constant tests), so
>>> you don't need to look at all the cases, just the one that interests
>>> you.
>>
>>
>> Since you and Steve Holden agree that a case statement is useful, why
>> don't you propose it for python, or add it to the wiki page for Python
>> 3000.
>
>
> Two simple reasons.
>
> 1. You forgot my previous comment that "in current Python the equivalent
> approach is, of course, a dictionary of some kind, though it's arguable
> whether this is as clean in many cases as a case statement would be."
I didn't forget that. I never read it, and I don't see the relevance to
my suggestion. Now that I've read it, I would hardly call using a
dictionary as a switch statement, the "equivalent". The fact that
people use a dictionary as a conditional is a python wart.
> 2. Just because something is "useful" doesn't mean it should be added to
> Python. The bar should be set much higher, and should include at least
> "and significantly better than any existing alternative way of doing the
> same thing." Now go read point 1 again... ;-)
Now go read my message again. I made a suggestion to you. I didn't say
that a switch statement should be added myself. I would never propose
that because the chances of it being added are microscopic.
> My point was not to suggest that I want a case statement in Python, nor
Neither was the MY point, which you seem to have inferred.
> even that a case statement is a good thing to have in a language (though
> it might be... it's not my place to say). My point was simply to point
> out that performance is not the only reason to use a case statement.
I don't think you could have misread my simple suggestion to you any
more completely than you did.
More information about the Python-list
mailing list