Braces are not Compiler-Fluff.

T. William Wells bill at twwells.uucp
Wed Jan 4 14:31:39 AEST 1989


In article <7300 at chinet.chi.il.us> john at chinet.chi.il.us (John Mundt) writes:
: In article <849 at unh.UUCP> jeff at unh.UUCP (Jeffrey E. F. Friedl) writes:
: >
: >In article <272 at twwells.uucp> bill at twwells.uucp (T. William Wells) writes:
: >>
: >>  I believe ...
: >>  that braces exist only to make the compiler happy and should
: >>  therefore be as unobtrusive as possible.
: >
: >    Several people have said this and I disagree. I suppose
: >that it's a matter of opinion, but to me braces are part of
: >the C language and as such I use them extensively as cues
:
: I agree that braces are needed as cues and would add the following:

I said that braces are *redundant* information. In other words, if
you indent the code correctly, the braces don't add additional
information.  In fact, that is tautological: if the braces *do* add
additional information, you've indented the program incorrectly.  At
best, they provide confirmation of what one should already know about
the program.

: At times, code being moved from one machine to another gets the tabs
: expanded into 8 spaces.  If a person takes the time to do a
:
:       g/        /s//^I/g
:           ^^^^^^^^ /* eight spaces */
:
: all will be well, but if not,

He deserves whatever grief he gets. Actually, if one puts tabs into
code, hoping that they will be interpreted as anything other than
eight space tabs, one is asking for grief. It's fine for one's editor
to treat an input tab as whatever number of spaces you want, but it
should put *spaces* into the file, not tab characters, not unless
they represent eight space tabs. Any other approach hasn't got a
chance of being portable. (And if you *really* want portability,
don't use tabs at all. Where I work, we compromise by allowing tab
characters at the beginning of a line only, and they represent eight
spaces exactly.)

:                               and a small piece of code is inserted,
: the compiler will be faced with a mix of spaces and tabs and would
: have a heck of a time figuring out what indentation was meant.
: Without the braces, there would be nothing visible to show the problem.

However, as I said, the braces should *always* be put in. This,
however, is mostly for the *writer* of the code: having the braces
always there can save him from embarrassing mistakes. For the reader,
the braces only contribute to a sense of uniformity; this permits the
reader to more readily understand the program.

: And finally, vi allows you to use the "%" command to see if you have
: braces matched.

The editor I use (Mined) can be made to move the cursor for a moment
to the matching brace, parenthesis, or bracket; this is even better.

---
Bill
{ uunet!proxftl | novavax } !twwells!bill



More information about the Comp.lang.c mailing list