WordPress.org

Make WordPress Core

Opened 14 months ago

Closed 11 months ago

Last modified 10 months ago

#50276 closed enhancement (reported-upstream)

PHP Coding Standards - Yoda Conditionals - Absolute Phrasing

Reported by: theistand Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: docs, coding-standards Cc:

Description

In the PHP coding standards page under the Yoda Conditionals it is stated
"When doing logical comparisons involving variables, always put the variable on the right side and put constants, literals, or function calls on the left side."
The concern being the use of the word "always" because at the bottom it is then stated "Yoda conditions for <, >, <=, or >= are significantly more difficult to read and are best avoided."

The issue with this is that <, >, <=, >= are in fact conditional operators and should apply to your standards with logical comparison. The emphasis "are significantly more difficult to read" implies that the decisions are on readability, however the entire purpose for the Yoda Conditionals has nothing to do with readability as it is the most illogical and unreadable implementation. The use of Yoda Conditionals should only be for ease in debugging.
Also quoting "Computer Science Terms" l-values stands for left-values and r-values stands for right-values. This is a logical approach and is a industry standard across the board which is the exact opposite as your call for use of Yoda Conditionals.

No argument on using them only pointing out some areas that can cause substantial confusion to newbies coming into the wordpress world.


Change History (3)

#1 @sabernhardt
11 months ago

  • Resolution set to reported-upstream
  • Status changed from new to closed

@theistand Thanks for the report!

Since this is not a core bug, the ticket fits better on Meta Trac. So I copied your summary and description over there:
https://meta.trac.wordpress.org/ticket/5429

This ticket was mentioned in Slack in #core-coding-standards by dd32. View the logs.


11 months ago

#3 @desrosj
10 months ago

  • Focuses docs coding-standards added
  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.