Search code examples
formattingcoding-stylepreferences

Should it be if() or if ()?


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!


Solution

  • 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.