bracing and naming

utzoo!decvax!ittvax!sii!mem utzoo!decvax!ittvax!sii!mem
Sat Oct 23 01:07:21 AEST 1982

  I am in favor of generally separating the body of conditional or
iterative piece of code from the entry statement to that code.  That
is, separating the argument from the if, while, for, do.  It seems
to me that since the braces are containers for that piece of code,
the braces should also be separate.  To me that seems clear.  The
two forms
              if (a == b) {
                 multiple statments;


              if (a == b)
                 single statment;

seem like inconsistent styles.  It makes no difference to me whether
the braces are indented with the entry statement or the argument; as
long as the convention is held throughout all code involved.  Personally
I prefer indenting the braces, but I can live with either.  Warren
Montgomery's recommendation about using braces if the single-statment
'code block' is not on the same line as the entry statement isn't
travesty, I've had that same thought.  It doesn't imply that the
newline becomes a syntactic entity any more than indenting code blocks
makes spaces and tabs syntactic entities; it simply helps programmers
avoid various pitfalls associated with omitting the braces.  Hail

   Referring back to the original c-style article by Walt Barnes,
I think that ALL compiler-only names ought to be capitalized.  By
this, of course, I mean symbols that aren't associated with storage,
including #defines, typedefs, and structure elements.  I consider
them ALL to be compilation parameters, whether handled by the
preprocessor or not.

  I use a slightly expanded set of rules for name forms, in addition
to the separations mentioned by Walt.  These are:

      SSS_EEE             A structure element.  SSS is a few CAPITAL letters
                            representing the structure type.  EEE is a
                            few CAPITAL letters describing the element.

      SSSptr              A pointer to a structure.  SSS is the structure
                            name, in caps, "ptr" appended to that.

      SSSadr              A global variable which is a pointer to a structure.

      _NAME               A #defined constant representing some value.

      NAME_               A #defined constant representing a bit mask.

  I have found in the past that being able to tell by the name of a symbol
what it represents is a great boon.  Unfortunately there aren't a lot
of special characters that can help in creating name forms.

Mark E. Mallett

More information about the Comp.lang.c mailing list