2

The Wordpress coding standards states to put spaces both inside and outside opening and closing parenthesis.

What is the rationale behind spaces on the inside of parenthesis? I've hardly ever seen that in any other code except PHP.

1 Answer 1

5

This is mostly just for readability. The semantics change before and after a parenthesis, and we are used to read spaces as word separators in western languages, so we can read such code faster.

Another point is search: If you want to search for all changes on variables beginning with $post it is easier to write a regex when you know there is always a space before and after. Doesn’t make a big difference, but still …

2
  • In addition to above, it doesn't matter if you develop for your own. If it's for upload to the wordpress.org directory it's about keeping the code base the same over the board so when you download a theme or a plugin you can easily orientate yourself around the code.
    – user19033
    Commented Apr 13, 2013 at 16:29
  • Although some of the reasons given aren't useful for me, they make sense and I can see how it may be useful to others. What's strange to me is that I haven't seen it used much at all in other programming languages. Maybe it's just one of those conventions that each language seems to have.
    – ivvi
    Commented Apr 14, 2013 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.