23

No switch () in python! Wtf!

Comments
  • 3
    Smell a conspiracy! @NoMad
  • 3
    No switch in Haskell?! Wtf?! There are languages which are not C-like.
  • 8
    You can easily implement something similar by using dictionaries tbh
  • 7
    IMO switch serves no real purpose other than syntax sugar. Not actually needed.
  • 6
    I was even more terrified to know there aint no ++ in python 😢 how do guys live without it?
  • 0
    the rejection notice at
    https://python.org/dev/peps/...
    shows there was no popular support for it at some conference
  • 0
    @TheCapeGreek it is useful when you are using enums or sum-types, since the syntactic sugar makes it easier for the compiler to warn you about missing cases.

    As a contributor to mypy I would love Python to have a switch, but there is no obvious syntax for it.
  • 0
    @TheCapeGreek That isn't an opinion, it's a fact. A pointless one to state, but a fact.

    It's pointless because most of every language is syntactic sugar, that doesn't mean you can't complain about extremely common and useful bits of sugar that some languages don't have for no immediately evident reason.
  • 2
    Switch is done by dict().get() and += 1 is much less error prone than ++.
  • 0
    But why cant we have both
  • 3
    @roh-7 because of PEP 20.

    https://python.org/dev/peps/...

    Especially
    "Special cases aren't special enough to break the rules."
    and
    "There should be one-- and preferably only one --obvious way to do it.
    Although that way may not be obvious at first unless you're Dutch."
  • 0
    Doesn't matter. Still love Python, as long as I don't have to put semi colon at the end of every line. Sometimes I forget and get a traceback because of a semicolon :P @kpenc @th31
Add Comment