I'm just learning python and realize that there's no switch-case in python. This really kills my mood to learning python. What do you think of this python programmers?
You're often advised to use a dictionary with functions instead, though that tends to break the natural flow of the code IMO.
Name:
Anonymous2010-11-20 17:40
That python doesn’t have a switch statement is a huge black mark on the language and, frankly is an absolutely stupid decision. Switch statements are more powerful than any ugly python hack.
“But then again using case/switch would violate python’s principle of using as few idioms as possible, so as to not confuse the average programmer.”
If switch statements are confusing, then that “programmer” should find a new field.
Name:
Anonymous2010-11-20 17:46
{'match': function}[case](parameters)
Name:
Anonymous2010-11-20 17:48
>>2
Yeah, sure
Everybody loves HUGE if else blocks. So easy to read!
And no dictionary can't really replace switch statement awesomeness (default, break, etc)
Chill out. One day Guido will figure out that the community is bored and will design a new language called Python 4. After a few years, a switch statement will be added as a feature to Python 3, which will be quite old by that time.
>>4 “But then again using case/switch would violate python’s principle of using as few idioms as possible, so as to not confuse the average programmer.”
... Really? That's the reason? Do I have bitch tits?
Name:
Anonymous2010-11-20 18:27
Lack of a switch-case construct is indeed one of Python's weaknesses. No, a combination of dictionaries and functions is not equivalent. Fall through is a feature. When I desire fall through like behavior in Python, I usually use closures with my elif blocks.
switch anus:
case 'a':
while something:
if something_else:
something = false
elif:
try:
blah()
except NullPointerException:
# do something
case 'b':
#...
default:
#...
Then, add one level of indentation if you put that in an infinite loop.
Python doesn't have a switch statement because it would be ugly as hell.
Name:
Anonymous2010-11-20 18:51
Fallthroughs are bad, you are a shitty coder if you need them