[wp-trac] [WordPress Trac] #44111: Setting data to variable early.

WordPress Trac noreply at wordpress.org
Fri Aug 20 20:29:37 UTC 2021


#44111: Setting data to variable early.
-----------------------------+-----------------------------
 Reporter:  rnaby            |       Owner:  (none)
     Type:  enhancement      |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Administration   |     Version:
 Severity:  normal           |  Resolution:  wontfix
 Keywords:  has-patch close  |     Focuses:  administration
-----------------------------+-----------------------------
Changes (by hellofromTonya):

 * keywords:  has-patch needs-testing close => has-patch close
 * status:  new => closed
 * resolution:   => wontfix
 * milestone:  Awaiting Review =>


Comment:

 Thank you @rnaby for your suggestion, reasoning, and patch!

 Circling back to review the patch and request.

 Core is filled with different patterns for setting the default state:
 - Pattern 1: within the `else`
 - Pattern 2: within the `:` of a ternary
 - Pattern 3: before the `if` conditional (proposed approach)

 All of these patterns are technically valid.

 An argument against using the proposed pattern (i.e. Pattern 3) is:
 performance. Why? If the conditional expression is true, then the variable
 is set twice. The performance hit here is tiny.

 What about readability? Readability would take precedence over this tiny
 tiny performance hit. However, IMO the readability of one over the others
 is subjective. For example, @rnaby prefers pattern 3 while some
 contributors find the `else` or ternary to be more clearly expressive and
 aligning to the concept of `if this do that; else do this other thing`.

 IMO there's not a compelling reason to enforce one pattern over the others
 through the coding standards nor to change the codebase to comply.

 Given that this ticket was marked as a `close` candidate 3 years ago with
 no progress, closing this ticket as `wontfix`. However if there's enough
 interest, a new ticket could be opened to discuss which pattern to adopt
 as the coding standard.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44111#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list