In the case of your tarot
example, it is *not* a violation of DRY, because the various elif lines
are not *sources* of knowledge which may contradict each other. The
worst that will happen is that if you change the variable name "tarot"
to something else, your code will fail with a name error.
motive in introducing a switch/case statement is to DRY, I think you
need a better motive.
> @Skip Montanaro: yes, switch statement is used in C also for codeThen I think we're not going to agree on the use or need for switch.
> optimization. Frankly, I think this aspect is unimportant for CPython in
> the present time.
Skip Montanaro writes:Sure, but Python already has such a jump table: a function-valued
> In other languages, the semantics of the switch statement allow the
> compiler to generate more efficient code. Instead of testing each
> branch of the if statement in succession looking for a match, you
> evaluate the switch expression once, then use it as an index into a
> jump table of some sort which points directly to the matching case
Here's a simple class that provides case like syntax. How would modifying the language be better than this?
I think case/elcase would be confusing as it would be unique to python and it's backwards -- the elcase keywords is used for the normal way that people use case statements while the case keyword implements the broken code that inexperienced C programmers frequently write.