开发者

Should it be if() or if ()? [closed]

开发者 https://www.devze.com 2023-01-17 05:50 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arg开发者_运维百科uments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 12 years ago.

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!


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.


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.


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.


If you are the only developer on the project, pick whatever you prefer, otherwise stick with whatever convention the team is using.


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


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消