On 2014-02-28, Marko Rauhamaa <ma...@pacujo.net> wrote: > Chris Angelico <ros...@gmail.com>: >> Python currently has dispatch tables and if/elif chains, and a >> strong cultural aversion to switch. You could change that by >> coming up with some *really* awesome proposal, but you'll be >> fighting against the tide a bit. > > It's easy have a "cultural aversion" when the language doesn't > provide the facility. > > Switch statements provide for excellent readability in parsers > and state machines, for example. They also allow the Python > compiler to optimize the statement internally unlike long > if-else chains.
Once you remove all the features of switch that wouldn't fit in Python, e.g.; fall-through, jumps, breaks; whats left provides negligible benefit over if-elif-else or dict-dispatch. A pythonic switch statement doesn't provide enough features to bother with its implemention. Check out Go's switch statement for an example of what it might look like in Python. Except you'd get it without labeled break or the fallthrough statement. Would you still want to use it? -- Neil Cerutti -- https://mail.python.org/mailman/listinfo/python-list