On Sunday, 7 April 2013 06:23:34 UTC+10, Phil Sturgeon wrote:
Hey Greg,
Thanks for stopping by.
It is implicitly disallowed. It is not explicitly or implicitly allowed. Therefore, it is disallowed by the standard.
I'm not sure I agree with this line of logic. Not only have several members of the team in various places state that "if ( ! " or "if (!" is persona preference, but just because something is not mentioned to be allowed does not mean it is banned.
Agreed, if (and only if) the standard didn't say anything that banned that formatting. But it does. Here is how I would have to code the logic in the sniff itself:
if ($spaceAfter === true && $nextChar !== T_LOGICAL_NOT) {
$phpcs->addError(...)
}
I have to add an *explicit* check for this type of code because it violates an existing rule of the standard. The fact that it is not mentioned in the standard means I should not be making an exception for it in PHP_CodeSniffer. There is no way of writing the check without explicitly looking for the T_LOGICAL_NOT token type.
I'm not sure what I am missing that causes you to disagree with my logic. I don't even use the PSR2 standard, so I'm not imparting personal preference into my reasoning.
Your comment about how various people have said it is due to personal preference seems irrelevant to me. Only because the standard is so clear on this point. It doesn't actually matter if all the voting members said it was allowed code. Writing code like that directly violates a MUST NOT rule in the standard and the voting members should vote to add an explicit exclusion into PSR2 if it was not the intention of banning this code.
Just because there is no rule saying "DocBlocks MUST NOT contain ASCII art of a unicorn jumping over a rainbow." doesn't mean im not allowed to decorate my docblocks with that beautiful horned creature.
Your example doesn't make any sense to me in this context, although it is amusing :)
I think a more relevant example is if the standard said "DocBlocks MUST NOT contain ASCII art of an animal" and then you decided to add an ASCII unicorn to a docblock. No, the standard does not explicitly say that unicorns are banned, and you can argue all day if a unicorn is actually an animal given it is imaginary, but the standard clearly bans your ASCII unicorn jumping over anything in this case. The standard would need to be changed to "DocBlocks MUST NOT contain ASCII art of an animal, unless the animal is imaginary". Then, you could go crazy with your unicorns and ligers.
Several people have said it is meant to be allowed as an option, so the fact that CodeSniffer shouts you down if you use this optional (and valid) syntax means that CodeSniffer PSR2 rules need to change.
Right?
Hopefully my comments above (and maybe below) have explained my reasoning a bit better this time.
To clarify, all im suggesting here is that the PSR-2 CodeSniffer rules will avoid showing an error for the "no spaces after opening parenthesis" rule in the case that the syntax "if ( ! " is used.
I assume that technically it's possible?
Yes, this is technical possible, and would be achieved in a similar way to my pseudocode above. It requires an explicit exclusion in the standard itself. Otherwise, I alone am then left defending why someone isn't getting an error for "if ( ! " even though the standard says it should be banned. That's how PHP_CodeSniffer got the check in the first place. Someone reported a bug [1] to me that I was not enforcing this part of the standard. They were right, I simply overlooked it.
It isn't my job to decide what a standard should enforce. I always have to have evidence and reasoning behind each decision and I have to constantly defend standards that I didn't write or even use. The thoughts of a group of people are hard to use as evidence as to why something is allowed. It is much better for that group of people to write their thoughts down, in the standard, as they originally did. Then, I can point to it and link to it and explain to developers why PHP_CodeSniffer is doing what it is doing, just as I did in your original bug report [2].
But you already know this. Your opening comment on this thread makes it clear that you understand that the written PSR2 standard bans"if ( ! " and you are looking for members to tell you that they were wrong and the standard should be ignored in this case. And that is what this discussion is all about. You CAN ignore a written part of the standard, just as developers who use tabs can. But I CANT ignore a written part of the standard because it is the evidence I need to validate why I coded a check the way I did.