home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!noc.near.net!hri.com!spool.mu.edu!sdd.hp.com!hpscit.sc.hp.com!hplextra!hpcss01!hpcuhe!defaria@hpcuhe.cup.hp.com
- From: defaria@hpcuhe.cup.hp.com (Andy DeFaria)
- Newsgroups: comp.software-eng
- Subject: Re: C Code Layout
- Message-ID: <45360003@hpcuhe.cup.hp.com>
- Date: 21 Dec 92 23:49:23 GMT
- References: <1992Dec15.023235.17090@seq.uncwil.edu>
- Organization: Hewlett Packard, Cupertino
- Lines: 70
-
- >/ hpcuhe:comp.software-eng / phardie@nastar.uucp (Pete Hardie) / 8:03 am Dec 18, 1992 /
-
- >>To me, such statements, while they require a close, should not require an
- >>open.
-
- >I disagree. Symmetry is desirable in a language.
-
- Symmetry for symmetry's sake is not a good argument in my book.
-
- >>In other words the assumption should be that I always have a compound
- >>statement and must tell the compiler when it's done.
-
- >Again, I disagree. Since a compaund statement is lexically identical to a
- >single statement, they should have the same form.
-
- Again a consistancy argument. While I agree that consistancy is important,
- I'm not often thinking about lexically identity when writing code. I'm more
- concerned with it's readablity, look and flow.
-
- >>C required that I also specify an open but I see no reason to devote a full
- >>line to it! I detest:
- >>
- >> if (condition)
- >> statement;
- >> statement;
- >
- >I don't quite understance why this bothers you.
-
- Because it's too easy to mess up the alignment and end up with:
-
- if (condition)
- statement;
- statement;
-
- and because it's too much of a bother to have to enclose it in braces merely
- to insert a debugging printf.
-
- If you argue for consistancy then by always specifying braces you are more
- consistant but my argument is more "Every if statement opens, look for the
- closing brace".
-
- >> if (condition) {
- >> statement;
- >> } /* if */
- >>
- >> statement;
- >>
- >>Note I label my terminating close (}). Now think about it. When eyeballing
- >>the above code and reading the if statement: Do you really care where it has
- >>opened or when it has closed? To me the open is inconsequential: Of course it
- >>starts but where does it end?
- >
- >I think that this is why I prefer the braces on separate lines - to make
- >their associations clear.
-
- Again, to me the opening brace is inconsisquentcial (sp?) and needless
- syntaxtic sugar. I guess I got this from programming in Modula-2 for a while.
- After working with a "all if's are compound - just tell me when they close"
- for a while I got used to it and said "This makes sense". Again this is only
- my opinion.
-
- >I dislike a comment that is placed for syntactic reference. I prefer
- >comments be reserved for semantic clarification. In some of the code I've
- >seen, there would be a forest of /* if */'s hiding the desired semantic
- >information.
-
- I got used to this from Ada and it's "end if"'s and the like. Again, it made
- sense to me to designate the end of such things as if's, while's, etc. Sure
- having more information about exactly what thing this is brace is closing
- would be even more helpful but then you have to duplicate the (condition)
-