[MUD-Dev] Languages
coder at ibm.net
coder at ibm.net
Sat May 17 13:44:14 CEST 1997
On 16/05/97 at 11:22 PM, cg at ami-cg.graysage.edmonton.ab.ca (Chris Gray)
said: >[John L:]
>: My only disagreement is with using the curly
>:brackets to distinguish code blocks. I think you score some good
>:points with better compiler parsing and debugging.
>:However, I think they are more convenient to type, easier to remember
>:and distinguish themselves better than 'fi', 'od', 'esac', etc.
>::-)
>Ah, but you have to count using the shift key in the convenience of
>braces versus short reserved words! :-)
>When I was designing a language like this a few years back, a friend
>commented that I really shouldn't be using 'od' to end 'for' and 'while'
>loops. Algol68 does that because it really only has one loop construct,
>and only the 'do' and 'od' are required. So, he said I should be using
>'rof' and 'elihw'. Maybe, but after I spoke 'elihw' to him for a couple
>of weeks he relented!
A key part of C's use of braces is implicit in the base design of the
language (and obvious when looking at the BNF diagram). In C, any place
that a statement can be used (in a non-expression context), a pair of
braces containing one or more statements can be used instead. Its a
slightly subtle and very pleasing piece of orthogonality, and is why:
if (x) y ();
is just as acceptable as:
if (x) {
y ();
}
and:
if (x) {
y ();
z ();
...etc.
}
I find this is one of the great beautiful simplicities of C over the the
do/od, if/fi, while/elihw type syntaxes.
There are lots of other more interesting examples, such as creating very
locally scoped automatics:
int funcx (...)
{
int var;
...code...
{
int var; // A new variable, unique from the one above
...code...
}
...mode code...
}
This last happens to be a trick I use a lot.
--
J C Lawrence Internet: claw at null.net
----------(*) Internet: coder at ibm.net
...Honourary Member of Clan McFud -- Teamer's Avenging Monolith...
More information about the mud-dev-archive
mailing list