Re: switch statement

new topic     » goto parent     » topic index » view thread      » older message » newer message
Critic said...

Well, if the compiler does common subexpression elimination, it is easy to optimize an if-elif-chain into a jump table. Speed is no justification for a switch/select statement nowadays, if you are going to have a proper optimizer anyway. But please get me right: I love "select"-statements. It's just that speed is no good argument to introduce them.

Um, speed was not at all the reason for implementing switch! In fact, when it was first introduced and decided on it was slower. I think in this thread you have had several examples of where a switch is less error prone than the current if/else syntax and more featureful due to fall-thru. Adding switch was never about speed nor optimizations. Many optimizations will be coming once we hit beta and further in 4.1.

I will say it again, because you might have missed it, but switch was decided to be added due to it being able to reduce the amount of work on the programmer. Fall thru was decided upon because it's the defacto standard for a switch statement, it's more powerful and we already have the capability of doing non-fall thru decisions.

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu