Message-ID: <38EBEA6D.D1E0E8BD@home.com> From: Robin Johnson Organization: Orbit Computers X-Mailer: Mozilla 4.7 [en] (Win98; U) X-Accept-Language: en,af,es MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Bracketing: A Matter of Style X-Priority: 2 (High) References: <38EBD03D DOT 895D1680 AT mindspring DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 78 Date: Thu, 06 Apr 2000 01:37:41 GMT NNTP-Posting-Host: 24.113.36.103 X-Complaints-To: abuse AT home DOT net X-Trace: news1.rdc1.bc.home.com 954985061 24.113.36.103 (Wed, 05 Apr 2000 18:37:41 PDT) NNTP-Posting-Date: Wed, 05 Apr 2000 18:37:41 PDT To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > That seems to me to be the most logical way to do it, for a variety of > reasons: > 1) The function is clearly visible, instead of being obscured, because > it is the only thing on the far left. This may seem trivial, but it > makes it much easier to skim through code looking for a particular > function. Use the search function, or failing that, use grep. > 2) All the contents of the function (or loop or whatever) line up, so > that it is easy to tell what is contained in what. The human brain is capable of recognizing complex patterns at a glance. > 3) It is easy to tell which brackets are unpaired (for those lazy folks > who always forget to close them), because the start and end brackets > line up. Hmm, doesn't your code editor have an option to highlight matching brackets? RHIDE does have the option for it. > 4) The white space helps separate chunks of code and thus make them > easier to understand at a glance. I agree with this point to a degree, but it is also worth noting that excessive whitespace restricts the overview of the function, if it is larger. > 5) Aesthetically speaking, it produces clearer, better-looking code > (imho). YMMV with what each person thinks look better. > I realize that most coders are almost religiously against this > bracketing system, and cling instead to the trendier style exemplified > thusly: We like to party just as much as the next guy, and have fun in our work. > int main(void) { > printf("Hello, World!"); > return 0; > } > int main(void); & int main(void) { return(0); } can look similar at a quick glance, because the semicolon and the curly brackets can be missed, and whitespace seen there instead. You might also want to take a look at the program called indent. It is available in the /gnu subdir on simtel. It will neatly format any code, however you want. For example, when I am doing some coding, and repeatedly working with modifying a particular function, by the end of the modifications, it will be quite mangled. So then just run it through indent, with your own settings, and it will look quite a bit better. It is also important to notice that things line up quite a bit more in our styles as well take for example: int main(int argc, char* argv[]) { for(int i=0;i<10;i++) printf("%i\n\r",i); return(0); } > This appears much more awkward, and it accomplishes little. The coders > are saving a single line of whitespace, while losing the aforementioned > benefits of the "lined-up" bracketing style. It still has the "lined-up" style that you mention, just on a different level than you expect. -- Robin Hugh Johnson "Robbat2" QTOD: "I used to be an idealist, but I got mugged by reality." E-Mail : robbat2 AT tesla DOT t-p-l DOT com ICQ# : 30269588 or 41961639 Home Page : http://robbat2.t-p-l.com Time Zone : Pacific Daylight (GMT - 8)