switch case for constants-only?
Nick Sabalausky
a at a.a
Sat Dec 5 17:10:22 PST 2009
"BCS" <none at anon.com> wrote in message
news:a6268ffdcba8cc43e0db895786 at news.digitalmars.com...
> Hello Nick,
>
>> Also, I still don't see how there's any semantic difference between
>> the current switch and the switch-like if-else chain other than just
>> the fact that switch currently carries the restriction that the values
>> being checked against must be unique and known at compile time.
>>
>
> For one; fall thought (but that can be done with gotos or some really ugly
> nested if's:
>
Right, it all maps out.
> The other thing is that a compiler is free to be implemented a switch
> statement any way it wants including things like perfect hashes or (for
> strings) a RegEx style DFA. This does have semantic effects in the O() of
> the construct.
>
I'd consider that more a matter of optimization. I know there's a lot of
people here that disagree with me on this, but I don't consider time
complexity a semantics issue, except for very, very explicit cases or
possibly for (true) real-time.
> I'll grant that what you are asking for is useful. But I will not go so
> far as to say that the current switch construct or even it's name (it has
> about as much to do with switch as for has to do with while)
*shrug* I've alwayd thought of while as nothing more than (a very welcome)
syntactic sugar for 'for'.
> should be co opted for it. I'll even go so far as to say that I really
> doubt that the current switch will atrophy even if another construct is
> added with these features.
>
>
More information about the Digitalmars-d
mailing list