[Python-Dev] Switch statement

Fredrik Lundh fredrik at pythonware.com
Fri Jun 23 09:35:19 CEST 2006

Phillip J. Eby wrote:

> I think I like it.  I was confused by what Fredrik meant by "const", but 
> your renaming it to "static" makes more sense to me;

footnote: I suggested static in my list of use cases; while "const" 
makes sense in many cases, "static" makes more sense for things like this:

>      def foo(value):
>          table = const {
>              1: "one",
>              2: "two",
>              3: fie.fum,
>          }
> (maybe "static" would be a better keyword?)

...at least for C/C++ heads; if you look things up in a dictionary, I'd 
say that the noun "constant", in the meaning

    2. a. A quantity assumed to have a fixed value in a
          specified mathematical context.
       b. An experimental or theoretical condition, factor,
          or quantity that does not vary or that is regarded
          as invariant in specified circumstances.

makes at least as much sense as the adjective "static":

    1. a. Having no motion; being at rest; quiescent.
       b. Fixed; stationary.

>> Unfortunately this would probably cause people to write
>>   switch x:
>>     case static re.DOTALL: ...
>>     case static re.IGNORECASE: ...
>> which is just more work to get the same effect as the
>> def-time-switch-freezing proposal.
> Without the "static", the reordering of execution isn't obvious.  But 
> perhaps that could be lived with, if the explanation was, "well, static
 > is implied by case".

I'd still prefer the "explicit is better than implicit" route, approach 
switch/case (if added) is defined in terms of if/elif, and optimizations 
are handled by the optimizer/code generator.


More information about the Python-Dev mailing list