CODING_STYLE and if blocks
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
if (a == 5) printf("a was 5.\n");
else if (a == 6) printf("a was 6.\n");
else printf("a was something else entirely.\n");It is something currently allowed by the CODING_STYLE document (there is no "indented statement"), but I am not fully comfortable with it. Should we accept such code? Should we fix CODING_STYLE?
Cheers,
Aurelien
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 5 lines · Aurelien Jarno
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
Quoted 8 lines
if (a == 5) printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");It is something currently allowed by the
CODING_STYLEdocument (there is no "indented statement"), but I am not fully comfortable with it. Should we accept such code? Should we fixCODING_STYLE?
I'd vote for fixing CODING_STYLE as that syntax makes my eyes hurt.
While CODING_STYLE is there as a guideline, good taste should still always prevail :-)
Regards,
Anthony Liguori
Quoted 4 lines
Cheers,
Aurelien
Quoted 10 lines · Anthony Liguori
Quoted 9 lines · Aurelien Jarno
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
if (a == 5) printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");
Quoted 8 lines
Quoted 4 lines
It is something currently allowed by the
CODING_STYLEdocument (there is no "indented statement"), but I am not fully comfortable with it. Should we accept such code? Should we fixCODING_STYLE?I'd vote for fixing
CODING_STYLEas that syntax makes my eyes hurt.While
CODING_STYLEis there as a guideline, good taste should still always prevail :-)
I think Uli only wrote the code as is because CODING_STYLE told him to always use braces around one-liner statements. I don't see how
if (a == 5)
printf("a was 5.\n");
else if (a == 6)
printf("a was 6.\n");
else
printf("a was something else entirely.\n");would be not readable. In fact I tend to use that code style myself a lot in places where it makes sense like:
if (r < 0)
return r;
It would really hurt my eyes to have braces on these simple ifs every single time.
Alex
Quoted 35 lines · Alexander Graf
Quoted 17 lines · Anthony Liguori
Quoted 9 lines · Aurelien Jarno
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
if (a == 5) printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");Quoted 6 lines
It is something currently allowed by the
CODING_STYLEdocument (there is
no "indented statement"), but I am not fully comfortable with it. Should
we accept such code? Should we fixCODING_STYLE?Quoted 4 lines
I'd vote for fixing
CODING_STYLEas that syntax makes my eyes hurt.While
CODING_STYLEis there as a guideline, good taste should still always prevail :-)I think Uli only wrote the code as is because
CODING_STYLEtold him to always use braces around one-liner statements. I don't see howif (a == 5)
printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");
Quoted 9 lines
would be not readable. In fact I tend to use that code style myself a lot in places where it makes sense like:
if (r < 0)
return r;It would really hurt my eyes to have braces on these simple ifs every single time.
It has been debated already a few times already, the argument against this it that it make patches more difficulty readable.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net
Quoted 5 lines · Aurelien Jarno
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
Quoted 7 lines
if (a == 5) printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");It is something currently allowed by the
CODING_STYLEdocument (there is no "indented statement"), but I am not fully comfortable with it. Should we accept such code? Should we fixCODING_STYLE?
In my opinion a line break and indent after the if () should be used except in the rare cases where keeping it all on a single line improves readability.
Signature · 2 lines
Måns Rullgård [email protected]
if (a == 5)
{
printf("a was 5.\n");
}
else if (a == 6)
{
printf("a was 6.\n");
}
else
{
printf("a was something else entirely.\n");
}Is in my opinion LOT CLEANER to debug.
This is my personal preference (comments included):
if (a == 5) // Check if it is 5
{
printf("a was 5.\n");
}
else // It was not 5
{
if (a == 6)
{
printf("a was 6.\n");
}
else // Neither was 6
{
printf("a was something else entirely.\n");
}}
Quoted 21 lines · Aurelien Jarno
Hi all,
I am currently reviewing the S390 patches which extensively use of code like:
if (a == 5) printf("a was 5.\n"); else if (a == 6) printf("a was 6.\n"); else printf("a was something else entirely.\n");It is something currently allowed by the
CODING_STYLEdocument (there is no "indented statement"), but I am not fully comfortable with it. Should we accept such code? Should we fixCODING_STYLE?Cheers,
AurelienSignature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net