-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
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
[Contributing] [Standards] Added entry for Yoda conditions #5402
Conversation
phansys
commented
Jun 15, 2015
Q | A |
---|---|
Doc fix? | yes |
New docs? | no |
Applies to | 2.8+ |
Fixed tickets |
This is part of the coding standards actually (and I'm quite sure it is already documented) |
I didn't see any entry about this @stof: https://symfony.com/doc/current/contributing/code/standards.html |
I thought it was mentioned. Can you update your PR to mention it on this page instead then ? |
@stof, updated. |
Use `Yoda condition`_ when you need to check a variable against a value. | ||
The main goal with this syntax is to avoid an accidental assignment inside the | ||
condition statements: | ||
|
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.
What if we reword this paragraph to make it much shorter?
Use `Yoda conditions`_ when checking a variable against a value to avoid an
accidental assignment inside the condition statements:
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.
@javiereguiluz, updated.
8ceac05
to
55d0a69
Compare
👍 I think this PR is now ready to be labeled as |
👍 |
Regarding to WordPress coding style from where Yoda condition from (AFAIK):
Is I understand well, Yoda condition should be avoided for If yes, it should be clearly specified on this doc too. |
---------- | ||
|
||
Use `Yoda condition`_ when checking a variable against a value to avoid an | ||
accidental assignment inside the condition statements:: |
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 think we should add this to the list of standards, instead of creating a custom section purely for one standard.
* Use `Yoda conditions`_ when checking a variable against a value to avoid an
accidental assignment inside the condition statements.
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 would also specify:
Yoda condition are not recommended for operators like `<`, `>`, `<=` or `>=`.
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.
@wouterj, you mean in structure section?
@soullivaneuh, I think there is no possibility of accidental assignment in <
and >
, so I agree with both of these.
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.
Moved inside "structure" section. It would be nice to know what others think about @soullivaneuh proposal.
@@ -100,6 +100,9 @@ Structure | |||
|
|||
* Place unary operators (``!``, ``--``, ...) adjacent to the affected variable; | |||
|
|||
* Use `Yoda condition`_ when checking a variable against an expression to avoid |
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 guess the correct wording would be "Use Yoda conditions" or "Use a Yoda condition" (the first sounds more natural to me).
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.
👍
| Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets |
d1e9207
to
844ac8e
Compare
@@ -100,6 +100,9 @@ Structure | |||
|
|||
* Place unary operators (``!``, ``--``, ...) adjacent to the affected variable; | |||
|
|||
* Use `Yoda conditions`_ when checking a variable against an expression to avoid |
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.
Please consider my comment: #5402 (comment)
Is contributors are agree with it of course.
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.
Yes @soullivaneuh, I'd like to hear more thoughts on this.
…s (phansys) This PR was submitted for the 2.8 branch but it was merged into the 2.3 branch instead (closes #5402). Discussion ---------- [Contributing] [Standards] Added entry for Yoda conditions | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | 2.8+ | Fixed tickets | Commits ------- 023a96f [Contributing] [Conventions] Added entry for Yoda conditions
Thanks @phansys! @soullivaneuh I took some liberty and added your suggestion at sha: d606f3e Cheers! |
* 2.3: Changed PhpStormOpener to PhpStormProtocol [#5402] Being explicit what this applies to (it should not apply to things like >=) [Contributing] [Conventions] Added entry for Yoda conditions Document security.switch_user event Added some more docs about the remember me feature Fixed a minor grammar issue Fixed a minor grammar issue Added support for standard Forwarded header Added support for standard Forwarded header Fixed issues reported by @xabbuh Remove the Propel book chapter and explain why we do that
* 2.6: Changed PhpStormOpener to PhpStormProtocol [#5402] Being explicit what this applies to (it should not apply to things like >=) [Contributing] [Conventions] Added entry for Yoda conditions Added the "payload" option back Show annotations first Reordered the code blocks to show Annotations, YAML, XML and PHP Fixed the issues reported by @xabbuh Finished the documentation of the new data comparison validators Added information about the new date handling in the comparison constraints and Range Document security.switch_user event Added some more docs about the remember me feature Fixed a minor grammar issue Fixed a minor grammar issue Added support for standard Forwarded header Added support for standard Forwarded header Fixed issues reported by @xabbuh Remove the Propel book chapter and explain why we do that
* 2.7: (21 commits) Changed PhpStormOpener to PhpStormProtocol [#5402] Being explicit what this applies to (it should not apply to things like >=) [Contributing] [Conventions] Added entry for Yoda conditions Added the "payload" option back Show annotations first Reordered the code blocks to show Annotations, YAML, XML and PHP Fixed the issues reported by @xabbuh Finished the documentation of the new data comparison validators Added information about the new date handling in the comparison constraints and Range Document security.switch_user event [#5332] typo [#5335] Minor tweaks Added some more docs about the remember me feature [Serializer] Updated the cookbook. Fixed a minor grammar issue Fixed a minor grammar issue [Serializer] ObjectNormalizer, object_to_populate doc. Minor enhancements. Added support for standard Forwarded header Added support for standard Forwarded header Fixed issues reported by @xabbuh ...
* 2.8: (22 commits) Changed PhpStormOpener to PhpStormProtocol [#5402] Being explicit what this applies to (it should not apply to things like >=) [Contributing] [Conventions] Added entry for Yoda conditions Added the "payload" option back Show annotations first Reordered the code blocks to show Annotations, YAML, XML and PHP Fixed the issues reported by @xabbuh Finished the documentation of the new data comparison validators Added information about the new date handling in the comparison constraints and Range Document security.switch_user event [#5332] typo [#5335] Minor tweaks document new Doctrine APC cache service Added some more docs about the remember me feature [Serializer] Updated the cookbook. Fixed a minor grammar issue Fixed a minor grammar issue [Serializer] ObjectNormalizer, object_to_populate doc. Minor enhancements. Added support for standard Forwarded header Added support for standard Forwarded header ...