When you have line of code with a parenthetical statement, do you include a space before the parenthetical?
For example, should it be
if()
or
if ()
Thanks in advance!
When you have line of code with a parenthetical statement, do you include a space before the parenthetical?
For example, should it be
if()
or
if ()
Thanks in advance!
It's definitely a personal preference (or a team preference when working with other developers) and really doesn't matter in the long run, but I (and everybody else I know) prefer no space.
Whatever you choose, just be consistent. Nothing bothers me more than looking at code that has multiple coding styles all mixed together with no consistency.
Subjective, but I prefer having the space because it looks cleaner, or maybe because that's just how I learnt to 'do it' with language constructs such as switch
, if
, while
and for
.
You could do it without the space if you like it to 'look like' a function call, because I don't use a space for function calls.
Visual Studio automatically changes it to if ()
, so I follow that.
I think it's marginally more readable, but the brackets provide some space already as it is so I think this is one of those totally-doesn't-matter things.
If you are the only developer on the project, pick whatever you prefer, otherwise stick with whatever convention the team is using.
In php it doesn't matter, but you probably knew that. I'm putting a space in between. I think it's more readable, probably because for functions I put no space in between and 'if' is not a function :)
I prefer keeping it to the default behavior of the IDE that I use, in order to reduce the risk of the source control system flagging insignificant differences between my edits and those of my co-workers. The same goes for other styling issues such as how many spaces to indent, whether to indent using space or tab and so on.
I prefer not to use a space, for me it makes it easier to read later and many of the people I know prefer no space as well for reading purposes.
You should use a space because not all languages use bracket delimited if statements. Leaving a space is the safer habit to get into.
Interpreters and compilers ignore it, So you can ignore it too!!!
It depends on if the compiler/language ignores white-spaces. (all though off the top of my head i can't think of any that would balk at the "if" statement with a space). Outside of the language specifics, it's your preference. That being said, I prefer no space as it makes the code look more concise.
It’s a matter of taste. I personally use the version with the space if ()
in order to distinguish this visually from a function call where I don’t use a space (as in mathematics).
Do whichever, but learn to read either without getting caught up about it.
Same deal as with bracket style.
There, that's about as meaningful an answer I can give to this.