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?
This rule will enforce consistency of spacing after the keywords if , else , for , while , do , switch , try , catch , finally , and with . This rule takes one argument. If it is "always" then the keywords must be followed by at least one space. If "never" then there should be no spaces following.
'if' isn't a function. It's a reserved word. Use the space.
One space before and none after an opening parenthesis or bracket within a sentence; no space before or after a closing parenthesis or bracket that is followed by a punctuation mark: Please read the enclosed booklet (Using Your Modem); it will help you take full advantage of your new communication tool.
Here's the rule: There should be a space before the open parenthesis and no space after it, and there should be a space after the closed parenthesis and no space before it.
I always thought that it was in order to differentiate them from function calls.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With