Space after if, while, etc (and before the paren)
Coding StyleCoding Style Problem Overview
Most coding conventions prefer putting a space after if
, while
, etc (if (
vs if(
). Is there a particular reason for this, or is that something that is a personal quirk?
Coding Style Solutions
Solution 1 - Coding Style
I always thought that it was in order to differentiate them from function calls.
Solution 2 - Coding Style
It's very subjective question, but there are code conventions. Example in Java: https://www.oracle.com/java/technologies/javase/codeconventions-whitespace.html
"Blank spaces should be used in the following circumstances: ...A keyword followed by a parenthesis..."
while (
or
for (
But with modern IDEs it's not a critical question anymore, in my opinion.
I prefer NOT to add a space in these cases (after keywords like for
, but in function/method calls function()
as well.
I think, function ()
is less readable.