Lang. suggestion: auto-fallthrough and comparison shorthands

Alksub Alksub_member at pathlink.com
Sat Jul 1 00:33:47 PDT 2006


I just found out about this language and was disappointed to notice that C++'s
switch syntax remains unchanged.  One of the most annoying mistakes in C++ is
forgetting to place a break statement in switch.  Breaks should be implicit, and
fallthrough should be explicit as it is more rare.  So something like:

switch (foo) {
case 0:
//Do something, then fall through
continue;
case 1:
//Do something; break is implicit
default:
//Panic
}

Another thing that might be cool would be mathematical-style transitive
comparisons, e.g. 1
if ([x < y < 45]) //...
would expand internally to the more cumbersome
if (x < y && y < 45) //...
e.g. 2
if (bar == [4 || 75 || 213]) //...
might become
if (bar == 4 || bar == 75 || bar == 213) //...
Although the two examples above somewhat strain the construct.

Alksub



More information about the Digitalmars-d mailing list