3 ms·
It's a bit weird that Python -- which in some ways was a trailblazer in popularizing somewhat unconventional syntax choices (indent matters!) -- has become so s
by Quekid5 8y ago
It's a bit weird that Python -- which in some ways was a trailblazer in popularizing somewhat unconventional syntax choices (indent matters!) -- has become so stuck in its ways that if-elif seems like a reasonable choice of syntax for what is usually a generalized switch[1].
[1]. The MultiWayIf extension for GHC is a great example of how to optimize this idiom for regularity.
- zephyrfalcon 8y agoswitch/case was, and still is, considered unnecessary in Python because it can be expressed just as clearly and concisely using if/elif/else. There was discussion about adding it, long ago, but (IIRC) Guido decided against it. It is not obvious what syntax switch/case should have in Python (two levels of indentation?), and its benefits are marginal at best. Then again, many things that supposedly would "never" make it into the language, have been added over time anyway, including the ternary if. So who knows...
- Quekid5 8y ago> switch/case was, and still is, considered unnecessary in Python because it can be expressed just as clearly and concisely using if/elif/else Ah, but it seems that there's some disagreement about this being unnecessary :). Btw, MultiWayIf is a much more powerful (bad word choice?) than 'switch' because it's more flexible at no additional syntactic cost. FWIW, I mostly just like it because of the extreme syntactic regularity of MWI. (I have no horse in the race. I just use Python occasionally as a scripting language, but I've been moving over to Haskell+Stack for scripts, so... )
- q3k 8y agohttps://github.com/q3k/switch4python https://github.com/q3k/switch4python :)