4 ms·
FWIW, 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
by raymondh 9y ago
FWIW, 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