[Python-Dev] Simple Switch statement (original) (raw)

Phillip J. Eby pje at telecommunity.com
Sun Jun 25 03:45:14 CEST 2006


At 05:30 PM 6/24/2006 -0700, Raymond Hettinger wrote:

[Phillip Eby] > I would like to be able to use switches on types, enumerations, and the like.

Be careful about wanting everything and getting nothing. My proposal is the simplest thing that gets the job done for key use cases found in real code.

It's ignoring at least symbolic constants and types -- which are certainly "key use cases found in real code".

Besides which, this is Python. We don't select a bunch of built-in types and say "these are the only types that work". Instead, we have protocols (like hash and eq) that any object may implement.

If you don't want expressions to be implicitly lifted to function definition time, you'd probably be better off arguing to require the use of explicit 'static' for non-literal case expressions.

(Your reverse mapping, by the way, is a non-starter -- it makes the code considerably more verbose and less obvious than a switch statement, even if every 'case' has to be decorated with 'static'.)



More information about the Python-Dev mailing list