-
Notifications
You must be signed in to change notification settings - Fork 27
switch case and default must not have semicolons #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
I don't think this is needed, since the example already uses colons, and the semicolon syntax is now deprecated in PHP itself. |
|
For some people, implicit/implied requirements as shown in sample code is not as clear-cut compared to when outlined in the prose of the requirements document, so this is still very much needed. |
|
I've changed the wording to below:
|
|
The description should probably mention that this will close #128. |
I've updated the description accordingly. |
| indented at the same level as the `case` body. There MUST be a comment such as | ||
| `// no break` when fall-through is intentional in a non-empty `case` body. | ||
| The `case` and `default` keywords MUST use colons as shown in the sample code below. | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
(Adjusted reference in the summary to match GitHub automation expectations.) |
|
@jrfnl Would this language be good enough for you? It's a bit wiggly in how it specifies things, but maybe that's OK in this case? |
| from `switch`, and the `break` keyword (or other terminating keywords) MUST be | ||
| indented at the same level as the `case` body. There MUST be a comment such as | ||
| `// no break` when fall-through is intentional in a non-empty `case` body. | ||
| The `case` and `default` keywords MUST use colons as shown in the sample code below. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `case` and `default` keywords MUST use colons as shown in the sample code below. | |
| The `case` and `default` keywords MUST use colons. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer the existing language, so that it also applies to formatting of the colons (e.g. there shouldn't be whitespace between case and :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there shouldn't be whitespace, that should be made explicit in the text. The code sample should demonstrate the intend of the text, not leave the reader to draw their own conclusions (which can be wildly different per person).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That the example applies to whitespace is already explicit in the text:
A
switchstructure looks like the following. Note the placement of parentheses, spaces, and braces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can only repeat what I said before:
The code sample should demonstrate the intend of the text, not leave the reader to draw their own conclusions (which can be wildly different per person).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A
switchstructure looks like the following. Note the placement of parentheses, spaces, and braces.
Perhaps adding colons to this list is enough and we call it a day?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I beg of you all, please read what I wrote before.
If you think it is acceptable for a standard to imply rules via code samples, just leave the code samples and get rid of all the rules.
If you want tooling like PHPCS and CS-fixer to write detection and fixing tools, the rules have to be made explicit in text as otherwise, the implementations of PHPCS and CS-fixer will differ (as has happened before). If the standard is open to different interpretations, it reduces the value of something being a standard and will only cause friction for the users of the standard.
I still think it's kind of redundant, but if this is being made explicit, than the text should be leading. The reference to the sample code like this, would be the only one of its kind in the whole document, so to me, it feels like it doesn't belong. If anything, the rule as described now, still leaves room for code like this - take note of the redundant curly braces -, which IIRC is discouraged: switch ($foo) {
case 10 : {
// Do something.
break;
}
}I wonder if PERCS should be explicit with an opinion about redundant curlies in this context if the use of the colon is being made explicit now anyway ? |
|
(With editor hat on) I'm open to not doing anything here if that ends up being the consensus. Or if the consensus is we should specify something, that's OK too. I don't have a large personal stake here. I... didn't know extra braces were legal, either. 😅 I'd be OK with forbidding those if the rest of the WG is. |
Update section 5.2 advising that semi-colons must not be used in switch statement.
Resolves #128