Re: how to make a macro work as a single line if stmt without braces

Liste des GroupesRevenir à cl c  
Sujet : Re: how to make a macro work as a single line if stmt without braces
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.c
Date : 30. Sep 2024, 03:29:10
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240929190456.954@kylheku.com>
References : 1 2 3 4 5 6 7 8
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-29, Keith Thompson <Keith.S.Thompson+u@gmail.com> wrote:
Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
[...]
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;
  }
[...]
>
Andrey, I hope you're aware that you're stating your own personal
preferences as if they were incontrovertible fact.
>
Readability is a combination of the text being read and the person
reading it.  I accept without question that *you* find K&R-style
brace placement "unreadable and unacceptable".  A lot of experienced
C programmers, myself included, either prefer the K&R style or
find both styles more or less equally readable.  And many prefer
vertically aligned braces but can deal with K&R-style braces.

For what it may be worth, the K&R style is pretty much baked into the
Awk language.  These two Awk programs are not equivalent:

/foo/
{
  foo++
}

vs:

/foo/ {
  foo++
}

The first one will print every record which contains a match
for the regular expression foo, and count every record.

The second will increment foo for every record that matches foo.

It is an undeniable fact that alignment and grouping is important
in visual design, and that use of these elements (and others)
is important in creating signs and displays that are easy to
grok at a glance.

Aligning opening and closing punctuators in programming is going
overboard though.

Here is why: we have already decided that these punctuators are
not helpful in helping us grok the structure of the code, and
instead rely on indentation.

The reason that the punctuators are not helpful is not because they are
not vertically aligned.

However, if we take away indentation from all the code other
than the braces, then the vertical alignment does help recover
some of the lost readability:

Compare:

  if (condition) {
  for (abc; def; fgh) {
  if (nested-condition) {
  whatever1;
  whatever2;
      }
    }
  } else {
  whatever3;
  }

versus:

  if (condition)
  {
  for (abc; def; fgh)
    {
  if (nested-condition)
      {
  whatever1;
  whatever2;
      }
    }
  }
  else
  {
  whatever3;
  }

But the likely reason for this is that the aligned braces increase the
amount of correct indentation. The structural cue from indentation is
only coming from the braces here, so if half of them are not indented,
then half that signal is gone.

I can sort of see why this identation signal from the opening braces
would be important even if the code were fully indented, to someone who
has some sort of cognitive quirk.

Also, I can see how the structure is more nicely conveyed when the
eopening braces are indented, if the reader temporarily blocks out
the visibility of the code and focuses on only seeing the braces:

This:

  {

    {

      {

 
      }
    }
  }

  {

  }

versus:

                 {
                      {
                        {


      }
    }
  }      {

  }

In other words, the vertical braces enable a mode of visually filtering
the code that may be of use to some. (Though, to me, choosing to see
the braces while suppressing the rest of the code seems wrongheaded. Or
wrong-eyed?)

It is mainly an indentation signal though; the main aspect is not the
vertical alignment, but the correct indentation nesting.  All the
matching braces are still vertically aligned in this code also, yet
the indentation is haphazard and unhelpful:

  if (condition)
      {
  for (abc; def; fgh)
    {
  if (nested-condition)
    {
  whatever1;
  whatever2;
    }
    }
      }
  else
       {
  whatever3;
       }

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
21 Sep 24 * how to make a macro work as a single line if stmt without braces61Mark Summerfield
21 Sep 24 +- Re: how to make a macro work as a single line if stmt without braces1Lawrence D'Oliveiro
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces50David Brown
21 Sep 24 i`* Re: how to make a macro work as a single line if stmt without braces49Andrey Tarasevich
21 Sep 24 i +- Re: how to make a macro work as a single line if stmt without braces1Bart
21 Sep 24 i +- Re: how to make a macro work as a single line if stmt without braces1Opus
21 Sep 24 i +* Re: how to make a macro work as a single line if stmt without braces5Keith Thompson
22 Sep 24 i i`* Re: how to make a macro work as a single line if stmt without braces4Andrey Tarasevich
22 Sep 24 i i +- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
22 Sep 24 i i +- Re: how to make a macro work as a single line if stmt without braces1David Brown
27 Sep 24 i i `- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
22 Sep 24 i +* Re: how to make a macro work as a single line if stmt without braces25David Brown
22 Sep 24 i i`* Re: how to make a macro work as a single line if stmt without braces24Kaz Kylheku
22 Sep 24 i i +* Re: how to make a macro work as a single line if stmt without braces21Bart
22 Sep 24 i i i+* Re: how to make a macro work as a single line if stmt without braces14Michael S
22 Sep 24 i i ii+- Re: how to make a macro work as a single line if stmt without braces1Bart
24 Sep 24 i i ii`* Re: how to make a macro work as a single line if stmt without braces12Tim Rentsch
24 Sep 24 i i ii +* Re: how to make a macro work as a single line if stmt without braces5Andrey Tarasevich
24 Sep 24 i i ii i+- Re: how to make a macro work as a single line if stmt without braces1David Brown
24 Sep 24 i i ii i+* Re: how to make a macro work as a single line if stmt without braces2Bart
24 Sep 24 i i ii ii`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
27 Sep 24 i i ii i`- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
24 Sep 24 i i ii `* Re: how to make a macro work as a single line if stmt without braces6Bart
24 Sep 24 i i ii  +* Re: how to make a macro work as a single line if stmt without braces2Keith Thompson
24 Sep 24 i i ii  i`- Re: how to make a macro work as a single line if stmt without braces1Bart
24 Sep 24 i i ii  `* Re: how to make a macro work as a single line if stmt without braces3Kaz Kylheku
24 Sep 24 i i ii   `* Re: how to make a macro work as a single line if stmt without braces2Bart
25 Sep 24 i i ii    `- Re: how to make a macro work as a single line if stmt without braces1Kaz Kylheku
22 Sep 24 i i i`* Re: how to make a macro work as a single line if stmt without braces6Keith Thompson
23 Sep 24 i i i `* Re: how to make a macro work as a single line if stmt without braces5David Brown
23 Sep 24 i i i  `* Re: how to make a macro work as a single line if stmt without braces4Richard Harnden
23 Sep 24 i i i   `* Re: how to make a macro work as a single line if stmt without braces3David Brown
23 Sep 24 i i i    `* Re: how to make a macro work as a single line if stmt without braces2Richard Harnden
23 Sep 24 i i i     `- Re: how to make a macro work as a single line if stmt without braces1David Brown
22 Sep 24 i i +- Modern text editor - 'bout time someone paid attention to keeping the thread title relevant!!! (Was: how to make a macro work as a single line if stmt without braces)1Kenny McCormack
22 Sep 24 i i `- Re: how to make a macro work as a single line if stmt without braces1David Brown
28 Sep 24 i `* Re: how to make a macro work as a single line if stmt without braces16Tim Rentsch
28 Sep 24 i  +* Re: how to make a macro work as a single line if stmt without braces5Michael S
29 Sep 24 i  i`* Re: how to make a macro work as a single line if stmt without braces4Tim Rentsch
29 Sep 24 i  i `* Re: how to make a macro work as a single line if stmt without braces3Michael S
30 Sep 24 i  i  +- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
30 Sep 24 i  i  `- Re: how to make a macro work as a single line if stmt without braces1Alan Mackenzie
29 Sep 24 i  `* Re: how to make a macro work as a single line if stmt without braces10Andrey Tarasevich
29 Sep 24 i   `* Re: how to make a macro work as a single line if stmt without braces9Tim Rentsch
29 Sep 24 i    `* Re: how to make a macro work as a single line if stmt without braces8Andrey Tarasevich
29 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Michael S
30 Sep 24 i     +* Re: how to make a macro work as a single line if stmt without braces3Keith Thompson
30 Sep 24 i     i`* Re: how to make a macro work as a single line if stmt without braces2Kaz Kylheku
30 Sep 24 i     i `- Re: how to make a macro work as a single line if stmt without braces1Janis Papanagnou
30 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch
30 Sep 24 i     +- Re: how to make a macro work as a single line if stmt without braces1Kaz Kylheku
30 Sep 24 i     `- Re: how to make a macro work as a single line if stmt without braces1David Brown
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Bart
21 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Mark Summerfield
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Ike Naar
21 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
21 Sep 24 +* Re: how to make a macro work as a single line if stmt without braces2Tim Rentsch
22 Sep 24 i`- Re: how to make a macro work as a single line if stmt without braces1Keith Thompson
21 Sep 24 +- Re: how to make a macro work as a single line if stmt without braces1Andrey Tarasevich
21 Sep 24 `* Re: how to make a macro work as a single line if stmt without braces2Blue-Maned_Hawk
24 Sep 24  `- Re: how to make a macro work as a single line if stmt without braces1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal