5 ms·
i would give anything to have a modern switch statement added to python. the justification for not having one does not hold water anymore. we even have enums in
by blondin 7y ago
i would give anything to have a modern switch statement added to python. the justification for not having one does not hold water anymore. we even have enums in the standard library but nobody uses them -- afaik -- because without a switch statement, enums are not really that useful...
- xapata 7y agoWhy would switch be useful? The interpreter would still need to evaluate in order like if/elif/else.
- jononor 7y agoA dispatch dictionary covers many of the typical usecases? https://alysivji.github.io/quick-hit-dictionary-dispatch.html https://alysivji.github.io/quick-hit-dictionary-dispatch.htm... Though I have missed switch statements a few times in Python, when implementing state machines - for parsing or sensor/actuator logic. Though these tended to be quite simple and not performance-critical, so a if/elif sequence was just fine.