Lang. suggestion: auto-fallthrough and comparison shorthands
Derek Parnell
derek at psych.ward
Sat Jul 1 04:10:06 PDT 2006
On Sat, 01 Jul 2006 17:33:47 +1000, Alksub <Alksub_member at pathlink.com>
wrote:
> 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.
These and other great ideas have been mentioned before. At best, these
sort of improvements will not be worked on until after v1.0 has been
released. However, the better semantics for switch is never going to get
implemented 'cos it will scare away too many C/C++ people, even if those
people would like to be more helpful. I think it has to do with the cost
of porting C/C++ code to D.
--
Derek Parnell
Melbourne, Australia
More information about the Digitalmars-d
mailing list