home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.software-eng:5130 comp.lang.c:18803
- Path: sparky!uunet!paladin.american.edu!darwin.sura.net!spool.mu.edu!umn.edu!csus.edu!netcom.com!netcomsv!ulogic!hartman
- From: hartman@ulogic.UUCP (Richard M. Hartman)
- Newsgroups: comp.software-eng,comp.lang.c
- Subject: Re: C code Layout
- Message-ID: <771@ulogic.UUCP>
- Date: 22 Dec 92 23:12:15 GMT
- References: <1992Dec17.081451@eklektix.com> <AJ3U.92Dec17172600@onyx.cs.virginia.edu> <1992Dec18.151710.23851@scott.skidmore.edu>
- Followup-To: comp.lang.c
- Organization: negligable
- Lines: 95
-
- In article <1992Dec18.151710.23851@scott.skidmore.edu> pvonk@scott.skidmore.edu (Pierre VonKaenel) writes:
- >In article <AJ3U.92Dec17172600@onyx.cs.virginia.edu> aj3u@onyx.cs.virginia.edu (Asim Jalis) writes:
- >>I prefer the K&R style of using braces with statement blocks:
- >>
- >> keyword (condition) {
- >> statement1;
- >> statement2;
- >> statement3;
- >> }
- >>
- >
- >I used to use this syntax until once I forgot one of the { and it
- >wasn't noticable. Took a while to find that bug. At least..
- >
- > keyword (condition)
- > {
- > statement1;
- > statement2;
- > statement3;
- > }
- >
- >is easier to spot. It's also more symmetric, which means from an
- >artistic view, more pleasing (I know, I know... subjective!)
-
-
- All this argument between style A:
-
- keyword (condition) {
- statement1;
- statement2;
- statement3;
- }
-
- and style B:
-
- keyword (condition)
- {
- statement1;
- statement2;
- statement3;
- }
-
-
- ... am I in the minority here by preferring style C:
-
- keyword (condition)
- {
- statement1;
- statement2;
- statement3;
- }
-
- This is essentially a minor variant with all the advantages
- of style B, but the additional advantage that the braces match
- the indentation level of the statements they surround, consider
- this -- if you have:
-
-
- if (cond)
- statement;
-
- and then have to add another statement to it:
-
- if (cond)
- {
- statement;
- statement2;
- }
-
- My editor (vi with auto-indent set) requires additional effort
- to move those braces back to the "outdented" position, whereas
-
- if (cond)
- {
- statement;
- statement2;
- }
-
- can be accomplished much quicker.
-
-
- btw: I really detest the K&R style (style A), for reasons
- already mentioned, among them (but not limited to):
-
- difficult to see block alignment
- hides "else" keyword
- even MORE difficult to make a single-line if-body
- into a block than style B
-
- -Richard Hartman
- hartman@uLogic.COM
-
- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- "Ideas are not responsible for the people who believe them."
-
-