[Tutor] Case ? (fwd)
Smith, Jeff
jsmith at medplus.com
Wed Jul 6 23:24:25 CEST 2005
If you like the switch statement (which I do) and believe Python should
have one (which I do) then you might take a look at this which someone
posted when I asked this same question a few months ago:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/410692
Jeff
-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On
Behalf Of Danny Yoo
Sent: Wednesday, July 06, 2005 4:29 PM
To: Tutor
Cc: mac at Wireless.Com
Subject: Re: [Tutor] Case ? (fwd)
> > It's a proposed enhancement:
> >
> > http://www.python.org/peps/pep-0275.html
>
> Since this didn't come out in Python 2.4, is it "automatically"
> re-considered for 2.5 ?
Hello!
It's still in the "open" set of peps:
http://www.python.org/peps/
so there's no guarantee that PEP 275 go in. I think there's still quite
a bit of revision and discussion ahead before it's ready for the
community. The PEP system is described here:
http://www.python.org/peps/pep-0001.html
> > in Python because it's not hard to use functions as values --- most
> > people haven't really missed case/switch statements in Python
> > because dispatch tables can be very effective.
[code cut]
> > where we're essentially mimicking the jump table that a case/switch
> > statement produces underneath the surface.
>
> Sure, this is nice.
>
> It does require one to "functionalize" each case, tho, rather than
> "doing the work" in the body of the case.
Yes --- although that restriction might be a good thing, to force
programmers to break their code into smaller functions. *grin*
Certain syntactic constraints in Python do put a cap on how complicated
or long our programs can be; I personally rationalize this as an attempt
to keep Python programs readable.
> > One other consideration about C's case/switch statement is its
> > bug-proneness: it's all too easy to programmers to accidently forget
> > to put 'break' in appropriate places in there.
>
> Years ago, I did this:
>
> #define is :{
> #define esac break;}
[code example cut]
Cute. *grin*
Aside: I'm not against the idea of that style of case analysis; I'm
starting to get infatuated with the more general idea of "pattern
matching" that other programming languages --- for example, PLT Scheme
and OCaml --- provide. But, unfortunately, I don't see anything like
pattern matching hitting Python anytime soon.
I just don't like how C does it, because it's so close to how the
underlying hardware works that it seems designed to be easy for the C
compiler writer to implement, rather than for the casual programmer to
use.
_______________________________________________
Tutor maillist - Tutor at python.org
http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list