About switch case statements...
Sean Kelly
sean at invisibleduck.org
Mon Nov 16 12:13:58 PST 2009
Andrei Alexandrescu Wrote:
> Chad J wrote:
> > So, switch-case statements are a frequent source of nasty bugs. Fixing
> > them (well) requires breaking backwards compatibility.
> >
> > Any chance this will happen for D2?
> >
> > (This is intended as more of a reminder and simple curiosity than a
> > discussion.)
>
> I wish very much that a transferring control flow statement (break,
> return, goto etc.) is required at the end of each case. Then, the rare
> case when you want to break through is easy to implement as goto case
> xxx; and all is good.
>
> Walter's answer to that has put me to silence for good. "But I use
> fall-through all the time!" I then knew the feature will never make it.
As long as it's possible to enumerate a list of matches for one case statement then I'm all for it. I very rarely use fall-through in any of my code but lexers/parser, where I enumerate lists of matches everywhere.
I'll admit to still being a bit peeved that I have to add default conditions where I only want a break, etc, but I'll concede that the safety is worth what I feel is unnecessary code. Just because "I never hit those bugs in my code" doesn't mean they aren't a common source of problems.
More information about the Digitalmars-d
mailing list