Re: Go ahead. Stop programming. This ensures you from any mistakes.



Ben Voigt [C++ MVP] <rbv@xxxxxxxxxxxxx> wrote:
Would you like to have the effect to a series of your program statements
by emulating the "fallthrough" by explicit goto after every statement? As
Bob http://www.bobcongdon.net/blog/2003/12/c-switch-statement.html points
it out, C# designers should introduce a "safe" must-break-switch rather
than "improving" the switch by disallowing fall-through and then adding
the goto junk.

No, forgetting a break is a common enough error that it's not unreasonable
to require an explicit flow control statement. What's wrong with C# is that
an MVP like Jon could not know that fall-through was available with the
"goto case" construct.

I'd say that's more of a fault with me than with the language :)

(Then again, there are various areas I don't know much about, if I try
not to use them anyway. I know very little about unsafe code, about
"goto" in general, and about any operator precedence which I wouldn't
want to assume that readers would know.)

The error message should be written more like:
Case block ended without flow transfer, you probably wanted "break" or "goto
case" but "return", "continue" or "throw" would also work.

That probably wouldn't have educated me, as I wouldn't have seen the
error often enough for it to be remembered.

And "continue" should definitely not be redefined to provide
fall-through, that would really make a confusing incompatibility with
C.

Yes, that's a fair point. How about continue with a case label? Still
too confusing? On balance, "goto" probably captures the intent
reasonably well.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Go ahead. Stop programming. This ensures you from any mistakes.
    ... with the added problem of fallthrough. ... As Bob http://www.bobcongdon.net/blog/2003/12/c-switch-statement.html points it out, C# designers should introduce a "safe" must-break-switch rather than "improving" the switch by disallowing fall-through and then adding the goto junk. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Using GOTO
    ... switch statement where you want to simulate fall-through. ... problem with Goto is that people overuse them and use them as slopppy ... Fall-through is related to C# mainly and only deals with switch statements. ...
    (microsoft.public.dotnet.languages.vb)