Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: Notesfiles $Revision: 1.7.0.8 $; site fthood Path: utzoo!watmath!clyde!cbosgd!ihnp4!inuxc!pur-ee!uiucdcs!uiucuxc!fthood!jrife From: jrife@fthood Newsgroups: net.lang.c Subject: Re: C bites / programming style [if Message-ID: <700003@fthood> Date: Tue, 10-Sep-85 09:34:00 EDT Article-I.D.: fthood.700003 Posted: Tue Sep 10 09:34:00 1985 Date-Received: Thu, 12-Sep-85 10:52:14 EDT References: <418@phri.UUCP> Lines: 90 Nf-ID: #R:phri.UUCP:-41800:fthood:700003:000:2744 Nf-From: fthood!jrife Sep 10 08:34:00 1985 Sorry that this response is rather long, but here goes... The reason I don't like: if(condition) { s1; s2; } can be shown by the following source: if (onelock(pid, tempfile, file) == -1) { /* lock file exists */ /* get status to check age of the lock file */ ret = stat(file, &stbuf); if (ret != -1) { time(&ptime); if ((ptime - stbuf.st_ctime) < atime) { /* file not old enough to delete */ return(FAIL); } ------------------------------------------------------------------------------ } ret = unlink(file); ret = onelock(pid, tempfile, file); if (ret != 0) return(FAIL); } stlock(file); When I listed the file out, the page break was right where the dashed line is. Now, I personally have a hard time figuring out which brace belongs to which, in this case. For one thing the braces around "return(FAIL)" are unnecessary, and this creates extra confusion, this time around. > Why do you like this style? This seems to indicate that >the braces are associated in your mind with the enclosed statements. You seem to have answered your own question. What else are the braces related to if not the enclosed statements? Note the following, which has nothing to do with if's, while's, for's, or do's. main() { int i = 42; float foo = 3.14159; printf("Starting program\n"); printf("i = %d, foo = %f\n",i,foo); { /* Truly local variables */ static char *foo = "What is the meaning of life?"; double i = 1.414; printf("Another message\n"); printf("i = %f, foo = %s\n",i,foo); } /* Back to the old variables */ printf("Yet another message\n"); printf("i = %d, foo = %f\n",i,foo); exit(0); } This is a program that, although useless, will compile with no problem. I think this points out the fact that only one logical statement is allowed after any of the control structures. The braces are required to turn more than one physical statement into one logical statement. Note, too, that I leave the original level of code flush with the right margin. This keeps the style correct, and is probably the explanation that you sought as to where I picked up this practice. I feel that the edge of the {paper,screen} does an adequate job as a delimiter, and think the extra white space is a waste. Secondly, my dislike for the construct that puts the braces in line with the if, while, or whatever, is shown by the the source to uusnap. Take a look at it, and you'll probably agree that some of those "{ statement" lines tend to get overlooked. -- ********************************* * * * Jeff Rife * * ihnp4!uiucuxc!fthood!jrife * * * * "Sorry about that, Chief." * * --Maxwell Smart * * * *********************************