"BartC" <> writes:
[...]
> But I have found that people don't seem like useful extra syntax in their
> favourite languages. Or perhaps more accurately, if their favourite language
> doesn't have a particularly handy construction, they will defend the lack
> of it to the death!
For C, there's a *lot* of resistance to any changes that would break
existing code.
New features that don't break existing code still have a very large
burden of proof that they're sufficiently useful to justify the
substantial cost of (a) defining them rigorously, and (b) implementing
them in *all* conforming implementations. The agonizingly slow adoption
of C99 is a prime example of what can happen when that's ignored -- or
even when it isn't.
> So, we don't need an if-else version of switch, because we can just use
> if-else, and the compiler will end up generating the same code anyway. But
> like you say, there would never be a reason to progress beyond if-then-goto
> in that case.
If you're talking about either changing the existing switch
statement, or adding a new kind of switch statement, that allows
non-constant labels and jumps to the first matching case, I honestly
don't see that it's much better than a sequence of if/else if/else
statements. Presumably it would test a given value against a
sequence of other values. Would those tests be limited to equality,
or would it permit "<", ranges, and so forth?
It would evaluate the given expression only once rather than
re-evaluating it for each test -- but that's trivally accomplished
by using a temporary variable.
Am I missing some significant advantage in expressive power, safety,
performance, or something else that would make a dynamic switch
worth adding to the core language?
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"