Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: c code "beautifier"

Author: Francesco Di Tolla

Date: 05:31:43 12/03/03

Go up one level in this thread



>I've always wondered why people like to have lines containing only a
>brace and nothing else.

because it is ANSI standard. And it is ANSI standard becasue it is easy to read

[..]
>if (ifClauseExample) {
>  for(forExample = 1; ;) {
>    if(oneLineIf)
>      shouldLookLikeThis(); }}
>
>Much more compact and readable, IMHO.

this is simply horrid :-)
the ANSI goes like

if (ifClauseExample)
{
  for(forExample = 1; ;)
  {
    if(oneLineIf)
      shouldLookLikeThis();
  }
}

the Kernighan and Ritchie like:

if (ifClauseExample) {
  for(forExample = 1; ;) {
    if(oneLineIf)
      shouldLookLikeThis();
  }
}

it is very important to be able to "read" which level of brace you're closing so
the closing brace is always on a new line.

Your piece of code is fine but if the function is say hundred lines (or even a
1000 lines) long, then reading:

...
   if(...) {
     .
     .
     .
        .
           .
             100 lines
                   somestatement;}

how do you know what is that brace closing? Many editors have a matching brace
utility but the indentation helps to "read" anyway.

regards







This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.