Suggestion: new switch statement
Rioshin an'Harthen
rharth75 at hotmail.com
Tue Aug 22 02:56:45 PDT 2006
"Chad J" <gamerChad at _spamIsBad_gmail.com> wrote:
> At the same time, I can't stand the fall-through default behavior! It
> is a source of bugs, and I've already been hit by it a few times in D
> and spent hours trying to find the bug in a switch statement that
> behaves subtly different than what I expected.
>
> I've read that this is maintained in D to keep it easy to port C code
> over to D. That's understandable, especially if you want to make break
> the default, which would change the meaning of code without any warning.
>
> I'd suggest though, that you don't allow a default ending for case
> blocks at all. Mandate that each case block be followed by an escape
> like 'break', 'return', 'goto', 'throw', etc. That way, the compiler
> would throw an error when C code that uses fallthroughs is inadvertently
> used as D code. Also, this is one of those things from C/C++ that is
> bad. D is supposed to get rid of those bad things even if it means
> losing backwards compatibility, so please get rid of this bad thing that
> comes from C.
>
> I also like Mike's suggestion on this thread a lot. It could even be
> combined with my suggestion. I'd say use Mike's suggestion, and only
> apply my suggestion to the colon blocks. Since the brackets and
> one-liners are not valid C syntax AFAIK, the compiler won't need to
> mandate anything about them to flush out bugs from incoming C code. On
> the developer side, this trades nasty runtime bugs for some small amount
> of hunting down compiler errors and fixing them. A good trade IMO. Not
> sure what the cost would be to compiler writers like Walter, but please at
> least implement the mandatory ending on the current case blocks, or
> something just as good.
Me, too.
I hate forgetting to type a break statement at the end of a case. It's
usually a pain in the *** to find. Enforcing the break, continue, etc. at
the end of a case is a good way to remove unnecessary bugs.
Thus, votes++
More information about the Digitalmars-d
mailing list