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. [...]
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?
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 }
On 09/28/24 5:02 AM, Tim Rentsch 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?
Er... The answer to his question is already present in the quoted
portion of my post. "The vertical spacing introduced..."
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?
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
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;
}
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.
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
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.
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++
}
[...]
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.
[...]
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?)
[...]
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
This readability problem exists one the other end with struct
declarations and `do{}while` syntax as well
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.
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.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 991 |
Nodes: | 10 (0 / 10) |
Uptime: | 119:24:00 |
Calls: | 12,958 |
Files: | 186,574 |
Messages: | 3,265,634 |