Sujet : Re: how to make a macro work as a single line if stmt without braces
De : andreytarasevich (at) *nospam* hotmail.com (Andrey Tarasevich)
Groupes : comp.lang.cDate : 29. Sep 2024, 15:41:14
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vdboub$1pcnk$1@dont-email.me>
References : 1 2 3 4 5 6
User-Agent : Mozilla Thunderbird
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;
}
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
typedef struct MyStruct
{
int a;
double b;
char c;
} MyStruct;
do
{
whatever1;
whatever2;
} while (condition);
although admittedly this has its own drawbacks.
-- Best regards,Andrey