Re: If you were inventing CoBOL...

From: Michael Wojcik (mwojcik_at_newsguy.com)
Date: 09/07/04


Date: 7 Sep 2004 14:38:16 GMT


In article <b7djj0dcl5pb7prmim2ditf36eiplr8ftq@4ax.com>, Robert Wagner <robert@wagner.net.yourmammaharvests> writes:
>
> Whoops. I should have said EXIT EVALUATE. There's no such thing. I
> made it up to compare with C, which requires an explicit exit
> 'break'. If you leave it out, the case statement continues running.
> Missing 'break' is a common form of bug.
>
> Some defend that, saying you might want it to continue if the program
> is a 'state machine'.

State machines have nothing whatsoever to do with it.

Default fallthrough was a deliberate design decision by Dennis
Ritchie, but it was made primarily to simplify implementing something
that clearly is a feature: multiple cases with a common body, as in

   case 1:
   case 2:
      action();
      break;

Some subsequent C-like languages that have removed default fall-
through (C#, for example) treat empty case bodies specially, so only
they fall through; that permits multiple case syntax while removing
the problem of accidental fallthrough. (C# overloads the goto
keyword for explicit fallthrough - unnecessary, since a normal C goto
with a normal label would also work, but a bit of syntactic sugar to
pacify fallthrough fans.)

That is clearly an improvement in language safety, but it complicates
implementation. It also arguably muddies the language design, though
since case is already a distinct C construct (basically a block-scoped
goto) another idiosyncracy hardly seems to matter.

-- 
Michael Wojcik                  michael.wojcik@microfocus.com
Today's Carnivore bait: Distracted by the Anthrax song, I let my bin,
laden with goods, crash into a bush.


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: Go ahead. Stop programming. This ensures you from any mistakes.
    ... fallthrough in switch statements in C. ... with the added problem of fallthrough. ... "improving" the switch by disallowing fall-through and then adding the goto ... given that I don't use it - but it seems odd to complain that the ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Structured Coding
    ... Microsoft is changing the language and even more so the APIs (and the ... The book I am reading is _Programming C#_ (hmm, ... Or perhaps C# simply is not a "first language" at all? ... Few people are fans of fallthrough, and I think this is an area where ...
    (comp.lang.cobol)