No more fall through in case statement?

S. S at s.com
Mon Jan 7 14:51:31 PST 2008


Bruce Adams Wrote:

> On Fri, 04 Jan 2008 00:15:25 -0000, S. <S at s.com> wrote:
> 
> > Carlos Santander Wrote:
> >>
> >> How about using existing D syntax?
> >>
> >> switch (s[i]) {
> >>       case ' ', '\t', '\f', '\r', '\n', '\v':
> >>           if (inword) {
> >>               r ~= capitalize(s[istart .. i]);
> >>               inword = false;
> >>           }
> >>           break;
> >>
> >>       default:
> >>           if (!inword) {
> >>               if (r.length)
> >>               r ~= ' ';
> >>               istart = i;
> >>               inword = true;
> >>           }
> >>           break;
> >> }
> >
> > This whole conversation about switch was kind of lost on me, but I have  
> > to contribute this.
> >
> > I, at various times, have written code that depends on case statements  
> > falling through, while not being identical!
> >
> > For example:
> >
> > switch(foo)
> > {
> > case 'bob':
> >     //Do bob stuff
> >     //Fall through and doo bar stuff too.
> > case 'bar':
> >     //Do bar stuff and exit
> >     break;
> >
> > case 'baz':
> >    //Do some baz stuff
> >    break;
> > }
> >
> > Whatever is changed shouldn't break this.
> 
> This whole conversation boggles me. cases should *never* fall through its  
> dangerous.

In other news, it has been discovered that the risk of choking is greatly increased by eating anything that is not pureed.  As a result, lawmakers have outlawed solid food.

Programming requires a brain.   

You should go read DailyWTF for awhile.  It is possible to do the most ridiculous things no matter how carefully the language is crafted.  We should just stay away from hand-holding and focus on making things easier.

I agree with measures that make debugging easier when dealing with naming and hijacking.  However, a simple step-through will reveal a case falling through when it shouldn't.  The aforementioned issues are not as easily caught.

-S.



More information about the Digitalmars-d mailing list