• Re: how to make a macro work as a single line if stmt withoutbraces

    From Michael S@already5chosen@yahoo.com to comp.lang.c on Sat Sep 28 20:30:48 2024
    From Newsgroup: comp.lang.c

    On Sat, 28 Sep 2024 05:02:05 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

    [...]

    And don't use "Egyptian" braces [the style used in the
    first edition of The C Programming Language, by Kernighan
    and Ritchie].

    This is the proper formatting style with braces

    if (failed)
    {
    ...
    }
    else
    {
    ...
    }

    The vertical spacing introduced by the `{` line provides
    separation between condition and the branch, which makes
    your code much more readable. [...]

    What qualities does this layout style have that make it "more
    readable", other than it being one that you like or prefer?

    { at the same level of indentation as its matching }

    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Michael S@already5chosen@yahoo.com to comp.lang.c on Sun Sep 29 12:48:35 2024
    From Newsgroup: comp.lang.c

    On Sat, 28 Sep 2024 21:53:06 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Michael S <already5chosen@yahoo.com> writes:

    On Sat, 28 Sep 2024 05:02:05 -0700
    Tim Rentsch <tr.17687@z991.linuxsc.com> wrote:

    Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

    [...]

    And don't use "Egyptian" braces [the style used in the
    first edition of The C Programming Language, by Kernighan
    and Ritchie].

    This is the proper formatting style with braces

    if (failed)
    {
    ...
    }
    else
    {
    ...
    }

    The vertical spacing introduced by the `{` line provides
    separation between condition and the branch, which makes
    your code much more readable. [...]

    What qualities does this layout style have that make it "more
    readable", other than it being one that you like or prefer?

    { at the same level of indentation as its matching }

    Certainly it is true that the layout style shown has the open
    brace at the same level of indentation as the matching close
    brace. What about that property makes this layout "more
    readable"? The statement given sounds like a tautology -
    I don't see that any new information has been added.

    It makes it easier to see where block starts and where it ends. Opening
    { followed by empty line is more bold visually than 'if something { ' or
    then '} else {'.

    Now, I can live with both styles, but can see why many people prefer
    style advocated by Andrey.



    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Michael S@already5chosen@yahoo.com to comp.lang.c on Sun Sep 29 18:04:31 2024
    From Newsgroup: comp.lang.c

    On Sun, 29 Sep 2024 07:41:14 -0700
    Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:

    On 09/28/24 10:47 PM, Tim Rentsch wrote:
    efer?

    Er... The answer to his question is already present in the quoted
    portion of my post. "The vertical spacing introduced..."

    Does that mean you think this

    if (failed) {

    ...

    } else {

    ...

    }

    is just as readable? Or is it something besides the
    vertical spacing that bears on your "more readable"
    judgment?

    No, the spacing in question is the spacing between the `if` condition
    and the first line of the the first compound statement.

    This is unreadable and unacceptable

    if (condition) {
    whatever1; /* <-- Bad! No vertical separation! */
    whatever2;
    }

    for (abc; def; ghi) {
    whatever1; /* <-- Bad! No vertical separation! */
    whatever2;
    }

    This is _immensely_ more readable

    if (condition)
    { /* <-- Good! Vertical space */
    whatever1;
    whatever2;
    }

    for (abc; def; fgh)
    { /* <-- Good! Vertical space */
    whatever1;
    whatever2;
    }


    It seems, you didn't understand the question.
    Tim was asking about your opining w.r.t.
    if (condition) {

    whatever1;
    whatever2;
    }


    --- Synchronet 3.20a-Linux NewsLink 1.114