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

Martin v. Loewis martin@v.loewis.de
Mon, 26 Nov 2001 23:58:05 +0100


> 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 would argue that all these beautiful properties of the other
languages do not carry over to Python.

E.g. in Prolog, you have only a two data types: structure, and list,
and neither is opaque: since they are not objects, their state is all
they have.

In Python, the same can be said just about lists and tuples, perhaps
dictionaries. Classes don't participate that easily in pattern
matching: If you have

x = httplib.HTTP()
x.connect("foo.com")

would you then expect that x matches httplib.HTTP(), or
httplib.HTTP("foo.com")?

In languages with pattern matching, you find that they use it to
emulate late binding: depending on the structure of a thing, you
perform different code. In Python, this is more easily done using
methods of the object, which naturally dispatch based on the type of
the object.

Regards,
Martin