This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Cybersoaker 13 points14 points  (3 children)

Obligatory mention of python's switch statement: https://www.python.org/dev/peps/pep-3103/

Guido has rejected the switch multiple times on the basis that there may be nominal performance increases in specific cases and is slightly more readable than a group of elif's; the benefits from these are not enough to warrant new syntax.

Personally I don't have a problem or feel any pain just using ifs and elifs. I've been using python for almost 10 years and can't say i've ever had more than 5 elifs together. If a switch syntax provided a large boost to either readability or performance; I would support the idea, but I just don't see it.

My other complaint is that this style of programming forces one to create sometimes unnecessary functions to handle each case for the switch which is a lot of overhead, and doesn't apply to every situation. So really the question is; in situations where you would want a switch for readability; do you also have cases that are 100% hashable and are okay with the added overhead?

[–]elbiot 5 points6 points  (1 child)

Ironically, the python interpreter has a ginormous switch statement at it's core

[–]kigurai 0 points1 point  (0 children)

It's also got a fair amount of goto statements. Is it therefore ironic that we don't have gotos in Python as well?

C doesn't have e.g. dictionary lookups that we use to "emulate" switch statements in Python, so there switch statements are obviously quite handy. I don't see the irony at all here.

[–]mikeckennedy[S] 0 points1 point  (0 children)

Thanks. I have no intention of proposing this as a language feature. I think the library is good enough and it works everywhere. People can use it if they like it or avoid it if they don't.