Follow up to: #254491: Standardize static caching
We should probably add also in the doxygen an example for a method+class for drupal_static(). E.g. see this comment http://drupal.org/node/254491#comment-1387384
Also, the code comments for drupal_static_reset()> should (according to bjaspan) make very clear that there should never be a reason to use it with the NULL parameter (i.e. a global reset via drupal_static_reset()) except from simpletest or similar "completely wipe Drupal's brain" situations. It must be clear that there is almost never a reason to use it outside the test framework.
| Comment | File | Size | Author |
|---|---|---|---|
| #36 | 422352-36.patch | 4.79 KB | sidharrell |
| #31 | 422352-31.patch | 4.77 KB | sidharrell |
| #31 | 422352-31.patch | 4.77 KB | sidharrell |
| #24 | improve_static_cache_comments-422352-24.patch | 2.32 KB | mac_weber |
| #21 | improve_static_cache_comments-422352-21.patch | 2.33 KB | mac_weber |
Comments
Comment #1
pwolanin commentedprobably suitable for a Novice
Comment #2
pwolanin commentedWe also need to update also the doxygen to say that if you have a variable name more complex than just __FUNCTION__, use a ':' to separate the suffix (this will avoid colliding with any other valid function name). e.g. :
Comment #3
RoboPhred commentedPatch includes drupal_cache naming, and drupal_cache_reset node on reset. The extra text for reset needs to be reviewed particularly, i'm not confident that is the right wording.
Comment #4
derjochenmeyer commentedThis line runs longer than 80 characters.
Comment #5
mac_weber commentedfixed comments to up to 80 chars long.
Comment #6
mac_weber commentedComment #7
pillarsdotnet commentedTagging for documentation team review. Also:
I found this confusing until I read it three times. Perhaps reword as:
The following construct lacks a clear antecedent for the indefinite pronouns "This" and "It".
Please reword as "This parameter should only be omitted ..." or "This parameter should never be omitted except ..." and describe the exact case where it would be appropriate to clear all static variables.
Comment #8
pillarsdotnet commentedAlso, this should be 8.x
Comment #9
pillarsdotnet commentedAnd then backported.
Comment #10
mac_weber commentedworks in D7 and D8
Comment #11
pillarsdotnet commented@#10 by Mac_Weber on October 18, 2011 at 3:48pm:
The pharase "should be used in substitute for" sounds awkward and non-standard to me. Please replace with "should be used instead of" or "should be use in place of" or else swap the order around and use "should be replaced with" or find another phrasing that sounds comfortable to native English speakers.
Otherwise the patch looks fine to me, but of course jhodgon has the final say.
Comment #12
mac_weber commentedI agree. Sounds better.
Comment #13
xjmTrailing whitespace here.
Also, note that the Drupal 8.x patch will need to be rerolled, because the core directory structure for Drupal 8 has now changed. (For more information, see #22336: Move all core Drupal files under a /core folder to improve usability and upgrades). When the patch has been rerolled, please set the issue back to "Needs Review."
Tagging as novice for the task of rerolling the Drupal 8.x patch.
If you need help rerolling this patch, you can come to core office hours or ask in #drupal-gitsupport on IRC
Comment #14
kathyh commentedPer comment #13, re-roll for D8/core, remove whitespace, merge to one patch
Comment #15
kathyh commentedComment #17
kathyh commented#14: improve_static_cache_comments-422352-14.patch queued for re-testing.
Comment #18
kristen polFor consistency, I'm wondering if:
__FUNCTION__
should be in double quotes since that is used for:
"__CLASS__ . '::' . __METHOD__"
?
Also, wouldn't an example be good here too or is the description sufficient? Or, perhaps combined with the following example?
This isn't part of the changes, but the wording:
"...a function can have certainty that there is no legitimate use-case..."
seems very awkward to me. I'm not even sure what is really meant. Perhaps, it means something like this?
"There are rarely legitimate use cases for resetting a function's static variable."
Comment #19
pillarsdotnet commentedProgrammers should provide the ability to reset static function variables unless there can be no legitimate use-case for resetting them. These rare exceptions should be justified by inline documentation.
Comment #20
kristen polThe text in #19 from @pillarsdotnet is human-readable :)
Comment #21
mac_weber commentedincluded suggestions from #18 an #20
Comment #22
mac_weber commentedComment #23
pillarsdotnet commentedIn general we avoid contractions and indefinite pronouns. Perhaps this would be better:
Comment #24
mac_weber commentedcorrections as suggested on #23
Comment #25
pillarsdotnet commentedShould wrap at 80 columns. Maybe delete the "Omit to reset all variables." sentence? Or maybe change to "Omit to reset all variables, but only in extreme cases such as with simpletest."
Otherwise RTBC, I think, but of course jhodgdon has the final word.
Comment #26
wryz commented#24: improve_static_cache_comments-422352-24.patch queued for re-testing.
Comment #28
mitron commentedThe semicolon does not belong in the following sentence:
This parameter should never be omitted; except in extreme cases where all data is being reset, such as with simpletest.
The sentence is self-contradictory. Never has no exceptions.
Consider something like "This parameter should only be omitted in extreme cases..."
Comment #29
sunGiven #1577902: [META] Remove all usages of drupal_static() & drupal_static_reset() , I think we should leave D8 alone and move this to D7.
For D8 it's good to have bad docs on these functions. Ideally, none at all. So that people stop using it. ;)
Comment #30
sidharrell commentedThink I have enough of a handle on the issue to be able to comment now.
Given that most of the remaining calls to drupal_static are in hooks that are not going to be removed prior to D8 release, I think we're going to have to live with these functions being in core, and therefore need do need some kind of documentation.
I would argue that we (is it we already), I mean someone, should change the doc to reflect that yes, these functions are here, but please don't use them. Please use OOP and protected properties, instead.
Comment #31
sidharrell commentedComment #32
mac_weber commentedI agree with @sun at #29. Changing version.
Comment #35
sidharrell commentedlooks like it tried to run the last patch against 7.x
I'll switch it back in a minute, after the test run.
Comment #36
sidharrell commentedComment #37
sidharrell commentedComment #38
joelpittetOne two many w's in that domain name.
And really, these are deprecated, wow. I use them all over the place! Glad I found this to read, thanks @Mac_Weber
Comment #39
joelpittetOh also the page is a 404 https://www.drupal.org/node/159902
Comment #40
joelpittetDrupal 8 it looks like this may be a duplicate of #2260187: [PP-1] Deprecate drupal_static() and drupal_static_reset()
For Drupal 7 I don't think we should be treating this as depracated and would consider close-won't fix/duplicate this issue as we don't have OOP as much in D7 to fallback on.
Comment #41
joelpittetComment #42
stefan.r commentedMarking won't fix based on #40