Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site npois.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!mtuxo!npois!adam From: adam@npois.UUCP (Adam V. Reed) Newsgroups: net.lang.c Subject: Re: C bites / programming style Message-ID: <411@npois.UUCP> Date: Fri, 6-Sep-85 17:58:48 EDT Article-I.D.: npois.411 Posted: Fri Sep 6 17:58:48 1985 Date-Received: Sat, 7-Sep-85 07:19:37 EDT References: <418@phri.UUCP> <700002@fthood>, <209@3comvax.UUCP> Organization: ATTIS, Neptune, NJ Lines: 36 Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes writes: > With regard to changing > > if(condition) { | if(condition) > s1; into { > s2; | s1; > } | s2; > | } > > [the idea is to indent the braces so that they are in the same column as > the statements they enclose] > > Why do you like this style? This seems to indicate that > the braces are associated in your mind with the enclosed statements. > In my mind, the braces are associaed with the 'if' statment, and > so they should be indented at the same column as the 'if'. I look for > the closing brace in the same column to be a sort of 'statement terminator' > (i.e. when I see it, I think "Ah, the end of the if statement"). > I've seen this unusual indentation style before, and I'm curious > if you developed a preference for it in learning some other language? According to K&R, Appendix A, section 9, the braces together with the declarations and statements they enclose form a single syntactic entity called "compound statement" or, equivalently, "block". This means that the braces are conceptually associated with the statements they enclose, and NOT with anything before or after. I use the form on the right exclusively, because I find it easier to keep a "block" together in my mind if it looks like, well, a single BLOCK. Except for people who have assimilated some very sloppy mental habits, programs are easier to read if visual entities correspond to syntactic and conceptual entities. I learned to align corresponding opening and closing symbols while coding in LISP, but I found the underlying psychological principle to be equally applicable to every language I encountered in the last 20 years. Adam Reed (ihnp4!npois!adam)