[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Why the fuck does Python not have switch statements? I've

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 20
Thread images: 3

File: transcendent.gif (3MB, 500x540px) Image search: [Google]
transcendent.gif
3MB, 500x540px
Why the fuck does Python not have switch statements? I've tried asking every forum I've ever been to and the best answer I could get was that it's not very "Pythonic".

What's the problem with a fucking switch statement and why is it not "Pythonic"?
>>
Python is shit and so are you
>>
Because python is a shit tier language for retards.
>>
>>57845588
Because functions are first class.

Just use a dictionary with keys as the cases of the switch and for the values use the function that you want to run.
>>
>>57845588
Switch statements are identical to looking up a function in a dictionary by key.
>>
>>57845588
Switch statements are for people who are too stupid to work out the logic of if-else-if statements. Also, python fuckin sucks dick, learn a better language.
>>
They were "too hard to parse" because Guido van Rossum is an uneducated child who never read a proper compilers book.
Same reason there's no multi-line lambdas.
>>
>>57847301
If-else ladders are very slow compared to switch.
>>
>>57846180
>>57846199
How do you handle default case with that? Catch exception if method not found?
Sorry if this sounds stupid, I don't really know python
>>
>>57847413
By using .get method

https://docs.python.org/3.6/library/stdtypes.html#dict.get
>>
>>57845588
why would you need a switch statement?
>>
>>57847408
If you're using an interpreted language, then you probably don't care much for speed anyway.
>>
No... switch... statement...
Are you fuckers serious?

This thread has to be a joke.
>>
>>57847472
Doesn't matter what the language is. The code should always be efficient.
Switch works like hash tables and will have a complexity of O(1)
>>
>>57847483
What makes you think this thread is a joke anon?
>>
>>57847515
Actually that largely depends on the language and compiler. I've seen GCC sometimes not generate jump tables for small switch statements.
>>
File: 1476736793435.jpg (276KB, 1000x1316px) Image search: [Google]
1476736793435.jpg
276KB, 1000x1316px
>>57845588
Sounds like an XY problem.
Tell me what you're trying to do.
>>
>>57847566
No need for switch statements when there are small number of cases anyway.
>>
File: 018 - LEmKh.png (466KB, 580x482px) Image search: [Google]
018 - LEmKh.png
466KB, 580x482px
>>57847483
why do you need them, anon, if you can accomplish the same thing with if / elif / else or dictionaries

Simple is better than complex.
There should be one-- and preferably only one --obvious way to do it.


:^)
>>
>>57847515
>Switch works like hash tables
Python has hash tables.
/thread
Thread posts: 20
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.