No more fall through in case statement?

Dan Lewis murpsoft at hotmail.com
Thu Jan 3 21:42:44 PST 2008


Steven Schveighoffer Wrote:

> "Janice Caron" wrote
> > On 1/3/08, Dan wrote:
> >> It's creative, and syntactically coherent.  I like it.  Even if it breaks 
> >> my old programs, this one makes sense.  : )
> >
> > I don't think it would break any old programs at all
> 
> I haven't done this in any d programs, but in C++ programs, I used to use 
> braces to create a scope in which to declare a variable.  What would happen 
> here:
> 
> case x:
> {
>     int y = 2;
>     ...
> }
> break;
> 
> I'm not super excited about there being such a subtle difference with the 
> colon (if you automatically put a colon without thinking about it, then the 
> break statement is required, meaning a very subtle bug), but other than 
> that, I like the idea.  Why not make it more obvious?:
> 
> case (x, y, z) // similar to case x: case y: case z:
> {
> }
> /* else case(a, b, c) ? */
> 
> -Steve 
> 
> 

I tend to agree with Steve.  Perhaps using case in the same manner as if/for/while/switch and the rest is more congruent to other program structures.  I also agree that falling through should be explicit.  I use it alot, but safe and more common behavior is to not do so.

I also like the comma notation; it would probably terse up the giant lexer switch a bit.

Regards,
Dan



More information about the Digitalmars-d mailing list