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.cDate : 30. Sep 2024, 03:03:20
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240929185229.787@kylheku.com>
References : 1 2 3 4 5 6 7
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-29, 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;
}
I don't see a readability difference. I'm not a kook.
Both examples use correct indentation.
The braces are placed such that the indentation does not lie.
If that is the case, you don't have to care how exactly they
are placed.
When I look at this code, my brain mostly sees it like this:
if (condition)
whatever1; /* <-- Bad! No vertical separation! */
whatever2;
for (abc; def; ghi)
whatever1; /* <-- Bad! No vertical separation! */
whatever2;
if (condition)
/* <-- Good! Vertical space */
whatever1;
whatever2;
for (abc; def; fgh)
/* <-- Good! Vertical space */
whatever1;
whatever2;
except that if there is something deceptive with the braces going on,
there is a good chance my brain will still alert me to it.
"Cuddled braces" is a very popular formatting style; it behooves you to
get used to it.
This readability problem exists one the other end with struct
declarations and `do{}while` syntax as well
>
typedef struct MyStruct
{
int a;
double b;
char c;
} MyStruct; /* <-- Bad! No vertical separation! */
>
do
{
whatever1;
whatever2;
} while (condition); /* <-- Bad! No vertical separation! */
>
I don't have a perfect solution for this variation of the same issue.
So, I tend to use
I don't understand what would be wrong with:
do
{
whatever1;
whatever2;
}
while (condition); /* <-- Good! Vertical separation! */
For the typedef you can always do this:
typedef struct MyStruct MyStruct;
struct MyStruct
{
int a;
double b;
char c;
};
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca