Suggesstion for standard upgrade

Discussion in 'C Programming' started by Jon, Oct 31, 2010.

  1. Jon

    Jon Guest

    A utility, written in (duh) Perl. ;) JK! A standard utility (written in
    C, for those of you "nice" (and one can only hope that you are) people
    who don't grok "the richness of the language that is English") that
    changes the *abhorrent* programming style of some, to something more
    decipherable.

    A. Example of the abhorrency:

    if (x) {
    // stmt 1
    // stmt 2
    }

    if (x) {
    // stmt
    }

    B. Which of course any *sane* programmer would instead write as:

    if (x)
    {
    // stmt 1
    // stmt 2
    }

    if (x)
    // stmt

    (There, I "said" that, just right). Disclaimer: I am not a compiler.
    Jon, Oct 31, 2010
    #1
    1. Advertising

  2. Jon

    Geoff Guest

    On Sat, 30 Oct 2010 23:50:44 -0500, "Jon" <> wrote:

    >A utility, written in (duh) Perl. ;) JK! A standard utility (written in
    >C, for those of you "nice" (and one can only hope that you are) people
    >who don't grok "the richness of the language that is English") that
    >changes the *abhorrent* programming style of some, to something more
    >decipherable.
    >
    >A. Example of the abhorrency:
    >
    >if (x) {
    > // stmt 1
    > // stmt 2
    >}
    >
    >if (x) {
    > // stmt
    >}
    >
    >B. Which of course any *sane* programmer would instead write as:
    >
    >if (x)
    >{
    > // stmt 1
    > // stmt 2
    >}
    >
    >if (x)
    > // stmt
    >
    >(There, I "said" that, just right). Disclaimer: I am not a compiler.
    >


    Such a tool exists. It's called GNU Indent. GIYF.
    Geoff, Oct 31, 2010
    #2
    1. Advertising

  3. Jon

    Tom St Denis Guest

    On Oct 31, 12:50 am, "Jon" <> wrote:
    > A utility, written in (duh) Perl. ;) JK! A standard utility (written in
    > C, for those of you "nice" (and one can only hope that you are) people
    > who don't grok "the richness of the language that is English") that
    > changes the *abhorrent* programming style of some, to something more
    > decipherable.
    >
    > A. Example of the abhorrency:
    >
    > if (x) {
    >    // stmt 1
    >    // stmt 2
    >
    > }
    >
    > if (x) {
    >    // stmt
    >
    > }
    >
    > B. Which of course any *sane* programmer would instead write as:
    >
    > if (x)
    > {
    >    // stmt 1
    >    // stmt 2
    >
    > }
    >
    > if (x)
    >    // stmt
    >
    > (There, I "said" that, just right). Disclaimer: I am not a compiler.


    Why is 'B' the "good" example? In the first half you have extra lines
    for your { } ... that just makes the file longer and not easier to
    read. Ultimately, indenting makes it easier to read, e.g.

    if (x)
    {
    do();
    }

    is harder to read than

    if (x)
    {
    do(x)
    }

    Which is easier to read as

    if (x) {
    do(x)
    }

    Since the visual information you need is the indenting on "do()" not
    the {} to tell levels of nesting.

    In the latter half of your 'B' example that form is actually dangerous
    as I've seen it numerous times turn into

    if(x)
    do();

    To something like

    if (x)
    debug_cmd();
    do(x);

    Which of course is wrong. Putting the {} braces around even a single
    statement co-routine is just smart since it allows ease of adding
    debug/additional code without worrying about flow.

    And as Geoff pointed out GNU indent can help you indent/space your
    code. It won't add/remove braces,etc though...

    Tom
    Tom St Denis, Oct 31, 2010
    #3
  4. Jon

    Seebs Guest

    On 2010-10-31, Tom St Denis <> wrote:
    > Why is 'B' the "good" example?


    Because he's trolling.

    Come on, calling the K&R style "abhorrent", referring to an alternative
    as what "any *sane*" programmer would use, arguing about indentation
    styles at all?

    100% pure trolling. You got hooked.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Oct 31, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HI can give suggesstion

    , Sep 18, 2007, in forum: C Programming
    Replies:
    0
    Views:
    323
  2. HI can give suggesstion

    , Sep 18, 2007, in forum: C Programming
    Replies:
    11
    Views:
    611
    CBFalconer
    Sep 25, 2007
  3. Mohammad Khan

    GUI .. Ruby .. Suggesstion

    Mohammad Khan, May 13, 2004, in forum: Ruby
    Replies:
    3
    Views:
    111
    Richard Dale
    May 14, 2004
  4. Graham Wideman
    Replies:
    1
    Views:
    77
  5. Replies:
    5
    Views:
    290
    Dr.Ruud
    Jul 5, 2006
Loading...

Share This Page