[Python-3000] Switch and static, redux

Barry Warsaw barry at python.org
Wed Jul 5 19:50:56 CEST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Jul 5, 2006, at 6:54 AM, Guido van Rossum wrote:

> So, my proposal is to give up on static, accept PEP 3103 with the
> following options:
>   - Syntax alternative 2+B (unindented cases, 'case in ...' for  
> multiple cases).
>   - Semantics option 3 (def-time freezing)
>
> Do we need any more discussion about the PEP before I pronounce? (I'm
> not super confident about the syntax alternatives yet.)

I've been away for a couple of weeks and unsub'd from this list, so I  
haven't followed all the discussions lately.  I have to say that PEP  
3103 is an excellent summary of all the issues, and in reading it,  
several of my preferences for a Python switch statement have, er,  
switched after reading it.  Thanks Guido!

While conceptually I agree with your conclusions on semantics, I  
think my gut still wants school 1a because to me that is the most  
natural way of thinking about how a switch statement should work.  I  
think that if that were adopted, there would still be value in a  
switch statement even without the optimization because it would be so  
familiar to people coming from other languages.  One of the questions  
I still get from time-to-time from Python newbies is why there is no  
switch statement.  Even after explaining if-chains, I still get a  
"yeah, but...".

My main concern with semantic option 3 is that the rules and  
restrictions it imposes will be confusing or obscure to the casual  
Python programmer.  Maybe in practice those restrictions won't  
ordinarily be visible, but I'm not sure we'll know until the feature  
is implemented and available for use.  I can suspend judgement for  
now because your arguments for semantic option 3 are so compelling  
(or rather, your arguments against the alternatives are so  
compelling).  I also don't have a good feel for whether those  
restrictions would be common enough that you'd end up falling back to  
if-chains most of the time anyway.  If that were the case, then  
switch wouldn't be worth the added language complexity.

As for the syntax question, the no-indent-for-cases make me queasy  
too, but maybe my opinion is clouded by my python-mode hat.  OTOH,  
I'm used to excessive indentation with try/except/finally so it  
doesn't bother me all that much (okay, okay, so we're trading one for  
the other :).  I strongly prefer 'case in' for multiple cases than  
any of the other alternatives.

I'd also be mildly in favor of default fall-thru a la C, but with  
'case in' I don't care too much.

- -Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (Darwin)

iQCVAwUBRKv8AHEjvBPtnXfVAQJmSQP+JAHMZ/F4MZiudju73oDKl2p3L8g0NKE4
yAuda7scht86uNC/ocHEcd+jMMugXNQBSyGWuuEXTj+7FpNTo9KHTWPqX5EJdWKf
5p3ly6tS7nSelYYPwA65cYm6kEz5byZL0bFmUfJGaE6DBWs1asZUZCs2KC6m2YYn
KVo309EL09c=
=UIRI
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list