[comp.lang.c] The D Programming Language, labelled blocks

g-rh@cca.CCA.COM (Richard Harter) (02/28/88)

In article <703@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes:
>In article <24935@cca.CCA.COM>, g-rh@cca.CCA.COM (Richard Harter) writes:
>> Here is an alternative to endif et al.  Use labels to start blocks and
>> 'end labels' to end them....

>He has just re-invented BCPL.

	Er, you give me too much credit.  A feature of BCPL, perhaps,
but not the whole thing> :-)

>Where C has { and }, BCPL had $( and $).
>The name for these was "section brackets".  There was an extra hack:
>"tagged section brackets".  If <id> looked like an identifier,
>$(<id> and $)<id> were tagged section brackets (each was a single token).
>So in BCPL this example would be
>	TEST boolean-expression THEN
>	    $(FOO
>		...
>	    $)FOO
>	ELSE
>	    $(BAR
>		...
>	    $)BAR

>PL/I has a similar feature, one can write
>	label: DO;
>	    statements
>	END label;	/* I may have this wrong */
>There is a difference, though.  In BCPL, the tags on the brackets must
>match exactly, but in PL/I a tagged END may close any number of tagged
>and untagged DOs.
>
>Can anyone who has experience with using this feature suggest why it has
>remained rare.  In particular, does anyone know why it isn't in C, given
>that it was in BCPL?  (Not that I think it's needed.)

As it turns out I do have experience with this exact feature in PL/I.
I once inherited a 40,000 line PL/I program with a 5000 line main program
which used nested tagged begin/end blocks.  I can tell you that multiple
closure is a real disaster.  Fundamentally, the problem is that you can
remove an end statement, thereby changing the block structure of the program,
and the program is still syntactically correct and compiles.  In a large
program which runs across many pages you can't visually confirm that all
the blocks align properly.  It's been a long time now, and I can't recall
the gory details any more.  However the practical effect was the same as
having a C switch construct with some of the terminating case 'break' 
statements unintentionally missing.

As a side point, I like the suggestion that someone made that there be
a fallthrough statement rather than automatic fallthrough.

As to rarity of usage, I suspect the problem is that it is a nice feature
if you use it in a standardized disciplined manner, but that if it is not
obligatory it will be used haphazardly, and that it has no particular value
in that case.   Now that I think on it, you don't need it for small pieces
of code, where everything is clear.  It may have some value for large
programs (as in large number of lines per file).  However my experience
is that the way to deal with the difficulties created by writing large
procedures is not to not write large procedures! :-).

OK, Richard, you win -- D should not have labelled blocks.


-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.

Ralf.Brown@B.GP.CS.CMU.EDU (02/29/88)

In article <24996@cca.CCA.COM>, g-rh@cca.CCA.COM (Richard Harter) writes:
}As a side point, I like the suggestion that someone made that there be
}a fallthrough statement rather than automatic fallthrough.

So, you would like to have to write
        switch(var)
           {
           case foo: fallthrough;
           case bar: fallthrough;
           case baz: fallthrough;
           case mung: /* code to do something for all four cases */
           }
?

Or add yet another special case (automatic fallthrough if and only if there
is no code between the two labels)?

--
{harvard,uunet,ucbvax}!b.gp.cs.cmu.edu!ralf -=-=- AT&T: (412)268-3053 (school)
ARPA: RALF@B.GP.CS.CMU.EDU |"Tolerance means excusing the mistakes others make.
FIDO: Ralf Brown at 129/31 | Tact means not noticing them." --Arthur Schnitzler
BITnet: RALF%B.GP.CS.CMU.EDU@CMUCCVMA -=-=- DISCLAIMER? I claimed something?