[wp-trac] [WordPress Trac] #37699: Death to Globals Episode #1: A Registry, A Pattern

WordPress Trac noreply at wordpress.org
Thu Sep 8 03:13:54 UTC 2016


#37699: Death to Globals Episode #1: A Registry, A Pattern
----------------------------+------------------
 Reporter:  wonderboymusic  |       Owner:
     Type:  enhancement     |      Status:  new
 Priority:  normal          |   Milestone:  4.7
Component:  General         |     Version:
 Severity:  normal          |  Resolution:
 Keywords:                  |     Focuses:
----------------------------+------------------

Comment (by dd32):

 Replying to [comment:84 jacobsantos]:
 > How is increased data on the debug output a valid argument?

 Anything can be a legitimate argument if it affects ones workflows.

 > Moving a global to a protected attribute is a valid refactoring
 technique recommended by experts. Furthermore allows for dependency
 injection at a later date. Which is considered a good thing.

 Yes, It's a valid refactoring technique, which adds zero benefit for
 WordPress. Referencing outside objects via a class method does nothing for
 code clarity or improving future code. All it does is hide the instance
 behind yet another layer of abstraction, something that doesn't give us
 any major benefits. Dependency injection can be done at a later date when
 it's viable regardless of this change.

 > How is it still a global? If the global changes, the internal object
 reference will not.
 A reference to a global, verses a direct global import is ultimately the
 same object, sure, you're accessing it differently, you're creating an
 extra memory reference to it, but it's still a global object which you're
 pulling in to every function you use it within.

 All this does is give you a fuzzy feeling of "Oh, Look at this, WordPress
 suddenly has 30 less uses of a global!" when in reality nothing actually
 changed, and it only added an extra layer in front of the developer for no
 benefit.

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


More information about the wp-trac mailing list