What's the recommended and / or required way to wrap the condition on an if
block?
For example, I have this block:
if ((islower(p[i]) && encrypted > 'z') || (isupper(p[i]) && encrypted > 'Z'))
{
// do stuff
}
I would prefer to think of the 80 character line length limit as a guideline rather than a rule. To me, having it all on one line seems easier to read and understand in this case. But style50
doesn't like it.
Obviously, this could be broken down into two separate if
statements or nested if
statements, but that's unnecessary duplication and a waste of processing power since the // do stuff
is the same for both.
Should I put a newline before the or, like this?
if ((islower(p[i]) && encrypted > 'z')
|| (isupper(p[i]) && encrypted > 'Z'))
... or after the or ...
if ((islower(p[i]) && encrypted > 'z') ||
(isupper(p[i]) && encrypted > 'Z'))
... I've also seen this ...
if (
(islower(p[i]) && encrypted > 'z') ||
(isupper(p[i]) && encrypted > 'Z')
)
... and this ...
if (
(islower(p[i]) && encrypted > 'z')
|| (isupper(p[i]) && encrypted > 'Z')
)
... and on and on it goes through many different variations and opinions on programming style.
What do the instructors / teaching fellows want to see?
Update:
Playing with this concept and style50
, I used this code:
int x = 5;
// If x is greater than 5 or less than 5, it's not 5.
if (x > 5 ||
x < 5)
{
printf("Not 5\n");
}
If I just hit enter after the ||
, style50
complains:
:( 6:14 Not enough whitespace after "||". Expected: 1, found: 0.
If I use the same code with a space after the ||
, style50
is happy.
Do they just follow what style50
reports without actually reading the code?
Thank you.