[Python-Dev] Re: switch statement (original) (raw)

Donovan Baarda abo at minkirri.apana.org.au
Tue Apr 26 04:20:07 CEST 2005


On Mon, 2005-04-25 at 21:21 -0400, Brian Beck wrote:

Donovan Baarda wrote: > Agreed. I don't find any switch syntaxes better than if/elif/else. Speed > benefits belong in implementation optimisations, not new bad syntax.

I posted this 'switch' recipe to the Cookbook this morning, it saves some typing over the if/elif/else construction, and people seemed to like it. Take a look: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410692

Very clever... you have shown that current python syntax is capable of almost exactly replicating a C case statement.

My only problem is C case statements are ugly. A simple if/elif/else is much more understandable to me.

The main benefit in C of case statements is the compiler can optimise them. This copy of a C case statement will be slower than an if/elif/else, and just as ugly :-)

-- Donovan Baarda <abo at minkirri.apana.org.au> http://minkirri.apana.org.au/~abo/



More information about the Python-Dev mailing list