dmd 1.046 and 2.031 releases
Derek Parnell
derek at psych.ward
Mon Jul 6 12:39:37 PDT 2009
On Mon, 06 Jul 2009 13:47:44 -0500, Andrei Alexandrescu wrote:
> Chad J wrote:
>> Walter Bright wrote:
>>> grauzone wrote:
>>>> No. Also, this final switch feature seems to be only marginally
>>>> useful, and normal switch statements do the same, just at runtime. So
>>>> much for "more pressing issues" but it's his language and not mine so
>>>> I'll shut up.
>>> The final switch deals with a problem where you add an enum member in
>>> one file and then have to find and update every switch statement that
>>> uses that enum. There's no straightforward way to find them to ensure
>>> the case gets added to each switch.
>>>
>>> It's solving a similar problem that symbolic constants do.
>>>
>>>
>>> The fall-through thing, though, is purely local and so much less of an
>>> issue.
>>
>> huh?
>>
>> These bugs always take me no less than 2 hours to find, unless I am
>> specifically looking for fall-through bugs.
>
> I agree. Probably a good option would be to keep on requiring break, but
> also requiring the user to explicitly specify they want fallthrough in
> the rare case when they do want it. I'd love to use "continue" for that
> but it's already "occupied" by cases like while (...) switch (...).
> Requiring !break or ~break would work but is a bit too cute. Adding a
> new keyword or a whole new switch statement is too much aggravation. I
> guess we'll have to live with it...
"too much aggravation" for whom? Certainly not for the coder, IMO.
Consider this syntax suggestion ...
int x = 1;
switch (x; fallthru) {
case 1:
write(1);
case 2:
write(2);
}
Output: 12
int x = 1;
switch (x; break) {
case 1:
write(1);
case 2:
write(2);
}
Output: 1
int x = 1;
switch (x; fallthru) {
case 1:
write(1);
break;
case 2:
write(2);
}
Output: 1
int x = 1;
switch (x; break) {
case 1:
write(1);
fallthru;
case 2:
write(2);
}
Output: 12
The default case
"switch (x) {"
would be the same as
"switch (x; fallthru) {".
One new keyword, and not a standard English word, allows all bases to be
covered. Too much aggravation for whom?
By the way, the above syntax format suggestion is because I see that the
syntax for 'switch' is ...
switch ( Expression ) ScopeStatement
and ScopeStatement is either a BlockStatement or a NonEmptyStatement.
Meaning that
switch (i) j = k;
is valid syntax! Why is that?
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
More information about the Digitalmars-d-announce
mailing list