[Python-Dev] Switch statement

Georg Brandl g.brandl at gmx.net
Thu Jun 22 21:19:48 CEST 2006


M.-A. Lemburg wrote:

> A nice side-effect would be that could easily use the
> same approach to replace the often used default-argument-hack,
> e.g.
> 
> def fraction(x, int=int, float=float):
>     return float(x) - int(x)
> 
> This would then read:
> 
> def fraction(x):
>     const int, float
>     return float(x) - int(x)

There's a certain risk that the premature-optimization fraction will
plaster every function with const declarations, but they write
unreadable code anyway ;)

Aside from this, there's still another point: assume you have quite a
number of module-level string "constants" which you want to use in a switch.
You'd have to repeat all of their names in a "const" declaration in order
to use them this way.

Georg



More information about the Python-Dev mailing list