Case Statements

Mark Lawrence breamoreboy at yahoo.co.uk
Wed Mar 16 05:51:23 EDT 2016


On 16/03/2016 09:35, Antoon Pardon wrote:
> Op 16-03-16 om 09:47 schreef Mark Lawrence:
>>
>>>
>>> Same with switch. You can use a hash table etc. to simulate switches,
>>> but only if the codeblocks are independent. Otherwise, if-elif chains
>>> are the way to go. Command line parsing is a case where switch
>>> statements are often used, e.g. in shell scripts.
>>
>> I've seen at least six different ways of simulating switches, so those
>> people who want them, can have them.  if-elif chains are not likely to
>> kill any Python programmer.
>>
>> I have no interest what other languages use switch/case statements
>> for, as we've on the PYTHON mailing list.
>
> There once were multiple ways to simulate a conditional expression.
> And it was generally thought that using if else statements instead
> of a conditional expression was unlikely to kill any Python programmer.
>
> But then one of the core developers was bitten by a nasty bug because
> he was using one of those constructs that simulated a conditional
> expression and soon enough Python had a conditional expression.
>
> So I guess those who would like a case statement in Python can
> only hope a core developer gets bitten by a nasty bug while using
> one of those ways of simulating switches.
>

So that core developers can waste their time putting something into the 
language that we've done without for 25 years, yes, that strikes me as 
extremely worthwhile.  Of course the change is actually trivial, as 
BartC has all ready pointed out. The work involved is shown here 
https://mail.python.org/pipermail/python-dev/2006-June/065827.html

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence




More information about the Python-list mailing list