Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!dali!milton!uw-beaver!Teknowledge.COM!unix!hplabs!hpda!hpcuhb!hpsqf!hpopd!daves From: daves@hpopd.HP.COM (Dave Straker) Newsgroups: comp.lang.c Subject: Re: Indentation (was Re: if (e1) return e2; [else] s1;) Message-ID: <7990008@hpopd.HP.COM> Date: 27 Mar 90 14:20:26 GMT References: <887@dino.cs.iastate.edu> Organization: HP PWD, Pinewood UK. Lines: 35 >chrisl@caen.engin.umich.edu (Chris Lang) / 11:21 pm Mar 25, 1990 / > >That reminds me to ask, what about this, which is basically my style? > >void foo(struct spam *bar) > { > if (bar->bletch != NULL) > { > printf("Ve haf a bletch!\n"); > } /* if */ > else > { > bar->bletch = 6; > printf("We have one NOW!\n"); > } /* else */ > return; > } /* foo() */ > >The point I am most interested in is the indentation of the entire function, >including opening and closing braces. Does this strike people as possibly >confusing? I find it clearer, and consistant (ie, every sub-block gets >indented, as do its opening and closing braces). I feel the final /* foo () */ >makes it obvious that we're at the end of a function, not one level in... >but what do others feel? If it helps you, and doesn't upset others who read your code, then it's ok. Personally, I think it's a waste of an indent to indent the whole function. Commenting ends of long loops to allow the reader to match it up to the start is good, especially if the loop falls off the end of a page. I either start each function on a new page, and/or (v. small functions only) put a comment bar/block between functions, which makes commenting the end redundant. Also, if you have nice small functions (< 2 pages, preferably 1) it's clear enough anyway. Dave