3 ms·
I'd have been using Python 3 ten years ago if they put something semantically useful in like a switch/case statement.
by halfnibble 9y ago
I'd have been using Python 3 ten years ago if they put something semantically useful in like a switch/case statement.
- raymondh 9y agoFWIW, I worked on a switch/case for Python about ten years ago and abandoned the effort because it reached a dead-end. Without the ability to mark variables as constants, a switch-case can't implement an efficient jump table. And without a jump table, a switch/case statement is merely syntactic sugar for an if/elif/elif chain.
- tonyedgecombe 9y agoI'd be happy with the syntactic sugar.
- sametmax 9y agoI don't see how it saves you that much of typing.
- halfnibble 9y agoIt's not about typing. It's about code legibility. With a series of if/elif's you have to mentally evaluate each condition to verify what's happening. If the use case really is switch/case, then a switch/case statement would allow the programmer to mentally evaluate only one condition and quickly glance at a list of possibilities.
- blickentwapft 9y agoIf/elif