[MUD-Dev] Languages

Miroslav Silovic silovic at srce.hr
Mon May 19 03:04:49 CEST 1997


> 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.

You misunderstand the point of the previous poster. The argument was
that the above is not very nice to the compiler. Consider this syntax
error:

if (foo)
   for (...) {
       statement;
       statement;
blah;
blah;
blah;

(note the missing '}'). In this case, compiler won't see that anything
is wrong till the declaration of the next function, and the programmer
won't get any useful error message. While, on the other hand,

if foo then
   for ... do
       statement;
       statement;
endif

(with missing endfor) bombs immediately, because the compiler notices
closing endif without matching endfor.
(and when you design language like this, you can still rule that
variables declared within for...endfor have local scope)

Note that this is the opinion you responded to, not *my* opinion.
You see, since any editor worth using will automatically indent lines
depending on syntax, unclosed '}' never happens to me. :)

	Miro




More information about the mud-dev-archive mailing list