[Python-Dev] re: PEP 275: Switching on Multiple Values, Rev 1.2

Brian Slesinsky bslesins@best.com
Mon, 26 Nov 2001 14:27:26 -0800 (PST)


> I'm not sure how your proposal fits in here, but it looks like
> the current if-elif-else syntax is better suited to it than
> some trying to use a switch-dictionary with some special objects
> to implement wild-card matching, e.g.

The wildcard object isn't very important; the part that matters is being
able to take structures apart using case clauses.  Also, this is mostly
about syntactical convenience - for certain problems, pattern-matched case
statements read better and are less error-prone than if-then-elif syntax.
But I need to come up with a better example.

Anyway, my main point is just to argue in favor of switch syntax rather
than looking for special cases of if-then-elif to optimize.  Some
languages do some very elegant things with switches that Python might want
to implement someday.  (I do appreciate that the dictionary optimization
only works for the simple case though, so comparison to constants is the
only part that's needed to start.)

- Brian