I agree with jhodgdon & webchick's assessment of the "3rd person" issue here. I also agree with agentrickard's assessment of the "implementation of" issue here, but when I put them together I don't get 1.
Given the resolution of the 3rd person issue, seasoned Drupaliers might expect that hook descriptions should be rewritten like this: implements hook_foo(). But since we're considering this issue, let's consider all the alternatives. The word "implementation" is generic, and the word "hook" is mysterious (i.e., cryptic to the uninitiated). When I was a Drupal newbie, they scared the crap out of me.
My proposition is to describe the hook functions (in 3rd person) in terms of what they do, rather than what they happen to be an implementation of. What a hook function does is this: it responds to a system-wide call or event. We should just say so, and name the event. I believe this would lower the scary bar for many people.
So the description for hook_update should say: Responds to node updates.
The description for hook_menu should say: Responds to URL requests.
...and so on. In some cases the developer may want to add a second sentence to further describe the function.
Your thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| #83 | 502190.patch | 193.59 KB | jhodgdon |
| #80 | 502190.patch | 195.47 KB | jhodgdon |
| #75 | 502190.patch | 194.29 KB | jhodgdon |
| #72 | 502190.patch | 190.38 KB | jhodgdon |
| #63 | drupal.hooks_.63.patch | 225.68 KB | sun |
Comments
Comment #1
jhodgdonI think that for seasoned Drupal programmers, it is important to have hook_foo() (which will turn into a link) somewhere in the first few words of the doc for a hook implementation function.
I also think that all doxygen function headers' one-line summaries should describe what the *particular* function does. I don't think repeating the generic description of the hook's purpose satisfies that; and given that hook_foo() will link to the generic hook's doc page, I don't see a lot of use in making that the standard. The hook implementations and hook doc will also tend to get out of sync, so I think this would become a maintenance issue.
So let's take a look at http://api.drupal.org/api/function/poll_update/7 as an example. Right now, the one-liner is
As If would propose changing this to:
But how about this instead:
This:
a) Includes a link to the generic hook doc
b) Tells us what the function is actually doing to implement the hook
Comment #2
As If commentedLove it. Your suggestion pleases all criteria for newbies and veterans alike, plus I think it would be useful for data mining & IDE purposes too (i.e., browsing for a function that does X).
Comment #3
webchick(Note: This is the opinion of webchick the Drupal hacker and not webchick the core maintainer. Feel free to disagree.)
The initial line of PHPDoc must wrap at 80 characters, so option #3 is out.
Additionally, I feel that "Responds to node updates." is:
a) Non-descriptive. Responds to whose node updates? Does what with the response?
b) Incorrect. This is an implementation of hook_update() which is what's actually called when the node is saved. hook_nodeapi_update() would be the one that responds to node updates. That's only in modules that don't define their own node type.
I personally would like to see this structured in such a way that API module can easily provide "backreferences" to hook implementations. So @see seems like a really nice way to handle this.
So maybe:
I would also actually recommend not postponing the "Make everything 3rd person" on this patch since if we do this right (or my definition of right ;)), all of these "Implementation of" summaries will be different, since they'll be descriptive of what the function is actually doing (like any proper PHPDoc function summary). It's going to take awhile to figure out what these all should be, if we go this route. And in the meantime, adding an "s" or an "es" is a very easy change that can go in quickly.
Comment #4
webchickOh. One additional reason to nix the suggestion of:
"So the description for hook_update should say: Responds to node updates.
The description for hook_menu should say: Responds to URL requests."
I think this would create a DX nightmare to have to stop every 4 seconds as you're writing your module to look up the proper API documentation string for whichever of the hundreds of hooks you're implementing. I'm a coding standards zealot, and even I can't picture myself doing that. :) Life is too short.
On the other hand, people who document their functions know how to document their functions. The only rules they need to know, which they can apply consistently, is:
1. Must be a 3rd-person description (this applies to all PHPDoc blocks, so it's an easy rule to remember)
2. Must include @see hook_XXX(), for hook implementations. We do a similar thing with @ingroup themeable for theme functions already.
Those are two small rules to learn as opposed to hundreds.
Comment #5
As If commentedPoint taken re #3. Rest assured I was being a little generic on purpose (my main point was about "responds to" vs "implementation of"), and I do believe jhodgdon is on the right track. But since you mentioned it, I actually grabbed my example from the current D6 hook documentation here...
hook_update developer/hooks/node.php Respond to node updating....guess I chose a bad example!
Comment #6
webchickOh no! :) Let's file a follow-up patch for "Make the docs for hook_update() not suck!" ;)
Comment #7
jhodgdonAre you sure about the 80-character thing? In JavaDoc and other autodoc systems I have used in the past, the "first line" extracted for the function summary went to the first period ("." or "full stop" for non-US English speakers), rather than being cut off by a carriage return/line break. But I am not sure about doxygen... Anyway, whether it is exactly 80 characters or not, the point remains that it needs to be short, so that it will display successfully on pages like
http://api.drupal.org/api/file/modules/search/search.module/6
Actually, looking at that page, some of the descriptions are almost certainly more than 80 characters, and they don't seem to stop on "." either. So my guess is that Doxygen is stopping at the first blank line in extracting the "short and snappy" description.
Anyway, I am fine with the hook_foo() link not being at the top of the doc, as long as it is somewhere, and I think having descriptions of what functions do would be infinitely better than "implements hook_xyz()" or any of its grammatical permutations. :) I vote yes for the example of #3 and the rules of #4.
Comment #8
webchickThe 80 character thing comes from the bot in #drupal. I'll ask Morbus to chime in here for more info on that.
Comment #9
morbus iffThe bot follows our own Doxygen formatting guidelines, which state (in "Documenting functions"):
There's no mention of line length there. I interpret the above as this being correct:
and this is OK too:
However, this is not:
Note, also, that the Doxygen standard itself asserts the same mentality (emphasis mine)
My Coder Tough Love project has a rule for this, called "Function summaries should be one line only." And, yes, Druplicon has code that checks for this as well, based on api.module's handling of summary in the database:
Comment #10
jhodgdonWell, it doesn't seem to be a *technical* limitation that the brief description be limited to one 80-character line. But I agree that it is a good idea. I've added this to the regular function doc section in the Doxygen standards page.
So, the idea would be to edit the "Documenting hook implementations" section to say something like this... let's see:
Documenting hook implementations
When documenting hook implementations, follow the same guidelines as for all other functions: The first line (limited to 80 characters) should contain a brief description of what this particular hook implementation does, beginning with a verb in the form "Does such and such" (third person). A longer description with usage notes may follow after a blank line, if more explanation is needed.
Generally, you should omit the
@paramand@returnsections documenting the parameters and return value of your hook implementation, since this would just repeat information available in the hook documentation. Instead, include a line like@see hook_foo()at the bottom of your documentation header, which will generate a link to the hook documentation in the API module (and on api.drupal.org). Example:Comment #11
drewish commentedsubscribing. i'd rather that we define the summary as the first sentence rather than the first line.
Comment #12
sunOn one hand, it is very good to force the summary to be on one line, because people do not make the mistake to write explanations then. (Explanations should follow after the summary.)
On the other hand, there are edge cases, in which it is impossible to squeeze a summary that makes sense into 80 chars. This happens quite rarely, but when it happens, a line exceeding the 80 char limit looks and feels strange.
On yet another hand, the current standard unveils many wrong PHPDoc summaries, where developers put entire novels into the summary.
Comment #13
As If commentedThose are the guys with three hands. ;-)
Comment #14
jhodgdonOK, how about this for the doc standard, to be placed on the Doxygen page:
- Documenting functions section... was (in part):
(then it goes on to talk about params and returns).
How about this as a new version of the above:
The first section of the block should contain a brief description of what the function does, and beginning with a verb in the form "Does such and such" (third person, as in "This function does such and such", rather than second person imperative "Do such and such"). If possible, this description should be limited to one 80-character line, and in any case, it should end with a period (".") and be followed by a blank line. A longer description with usage notes should follow after the blank line, if more explanation is needed.
- Documenting hook implementations section (which is immediately following the Functions section) -- proposed new text:
When documenting hook implementations, follow the same guidelines as for all other functions. Start with a brief description of what this particular hook implementation does, beginning with a verb in the form "Does such and such" (third person), if possible limited to a single 80-character line, and ending with a period (".") and a blank line. A longer description with usage notes may follow after a blank line, if more explanation is needed.
Generally, you should omit the
@paramand@returnsections documenting the parameters and return value of your hook implementation, since this would just repeat information available in the hook documentation. Instead, include a line like@see hook_foo()at the bottom of your documentation header, which will generate a link to the hook documentation in the API module (and on api.drupal.org). Example:Comment #15
morbus iff-1 from me, personally. As tha_sun states, too-long summaries are edge case rarities. The revised summary approach would make us incompatible with the Doxygen guidelines, UNLESS the particular configuration value JAVADOC_AUTOBRIEF is set. I would prefer that our internal documentation stay as close to "default" Doxygen as possible.
Comment #16
jhodgdonWasn't aware of that. So we should probably remove the "if possible" and "in any case" from the latest proposal.
People will always violate the guidelines anyway. So maybe even if we think it might, in extreme circumstances only, be OK to violate the 80-character rule, we should have it in there as the guideline?
Comment #17
jhodgdonComment #18
webchickI'm +1 for no ambiguity in the guidelines. Just remove the "If.." altogether. "This description should be..."
Comment #19
jhodgdonOther than that, are we agreed on the standard above? If so, I will edit the doxygen page and we can close this issue finally, and then file separate issues and patches for all of the many function docs that don't follow the standard.
Comment #20
drewish commentedjhodgdon, as well as issues against coder and api.modules so that they're all enforcing the new, unambiguous standard.
Comment #21
EvanDonovan commented#14 sounds great. I really didn't like "Implementation of" & either "Implement" or "Implements" was too terse.
Comment #22
morbus iff@drewish#20 and @stella: my Coder Tough Love already has rules for one-liner summaries and longer-than-80-character documentation lines, so we can just steal those from there. API.module would still need to be fixed.
Comment #23
stella commentedyeah, we can add it to the coder module. Morbus has already done most of the work :)
Comment #24
jhodgdonI've updated the instructions for documenting hooks on http://drupal.org/node/1354, since it seems we are all in agreement. I took out the "if possible", and made no changes to the standards for non-hook functions. If someone's unhappy, feel free to edit or suggest changes. Until then, this Documentation issue is hereby declared "fixed". :)
Rather than changing this to a Coder issue, I filed a separate issue: #521452: Update to check for new function header doc standards
I'm not sure what changes, if any, would be needed for the API module, as drewish suggested in #20. It seems like the API module would parse the doc correctly with the new standards? Or maybe #514404: One-line function descriptions adding additional text inappropriately takes care of this somehow? Not sure... Someone who knows what changes would be needed for API could please file an issue on that. Thanks!
Comment #26
sunRe-opening and tagging.
http://drupal.org/node/1354 still contains
which is entirely inconsistent now, because we use the third-person form everywhere else. And since users start to complain about PHPDoc summaries not following exactly what's noted there, while what is noted there does not make sense, I'm marking this critical.
I guess the fix is simple (just make "Implement[s]" plural), but won't alter that page without confirmation.
Comment #27
jhodgdonThis issue was about creating the standards for documenting hook implementations, which is done.
It is a separate issue that much of Drupal 7 is out of compliance with the current doc standards. Or many separate issues -- the procedure is that one issue => one patch, and there is no way we should/could file one big patch to fix the entire Drupal 7 code base to bring it all into compliance. I think it's going to take a very long time until it is all in compliance.
So I suggest submitting other issues like #525596: Standardize function doc for actions, bootstrap, and batch include files when you have the time/energy to fix a module or include file or two, or when you notice that a given module is out of compliance (most are). And we should make sure that any new doc that is committed complies with the current standards.
Comment #28
sunI must be speaking Spanish or Greek. I did not refer to any particular code in HEAD, but instead, I referred to the coding standards handbook page for documentation/PHPDoc. Specifically, I referred to that exact page, as known as http://drupal.org/node/1354. The code snippet was copied 1:1 from there, so I'm not sure how you come to your conclusion.
Anyway, good luck. The new standards make zero sense to me, so I won't adhere to those new changes anyway. Reverting to previous status, because it seems you wanted to revert the status.
Comment #29
jhodgdonI am reopening this for discussion, because Drewish apparently decided to revert the changes that had been made to the coding standards doc on July 27, with no discussion here, even though my previous edit referred to this issue node.
See http://drupal.org/node/1354/revisions
What do you want to do?
Comment #30
jhodgdonAnd sun: regarding your recent comments here -- I hadn't been aware of the changes to the standards doc, so I apologize for not understanding what you were bringing up.
Comment #31
morbus iffDrewish noted in IRC that his revert was partially aghast at "a full paragraph about what every hook implementation does", and his revert matches that, primarily deleting a large portion of documentation regarding hook_block().
I think, though, @drewish, that it might have been too hasty. I will heartily agree that describing what "hook_block()" does is pointless (and any other common hook). But the documentation that was deleted didn't really describe what hook_block does(), but described what blocks were being created in this particular implementation of hook_block(). Instead of describing hook_block(), the implementation, it described what blocks, specific to this particular module, were being created. I agree with that (though, I probably won't ever follow it either cos, in hook_block, as in hook_menu or hook_theme, it tends to be self-documenting based on function names, etc.).
The other major portion of documentation removed, regarding absentee @params and @returns for known hooks, removed was simply added back, in a different form, so there's no real argument there.
As for the rationale that "core doesn't do this", it's bunk. The code and doc standards have always been far ahead of what core actually does, and core fails in Coder and Coder Tough Love in dozens of places. It's a "do what I say, not what I do" sorta thing. Yes, they should be fixed (and my Druplicon's been saying that for years in its function lookups ;)), but reverting based solely on "what core does" shouldn't be weighed.
Comment #32
jhodgdonThe whole point of having documentation headers on functions is that someone should be able to figure out from the doc header what a function does, and not have to read the code. Right? Otherwise, let's just scrap doc headers completely and force everyone to read the code for all functions.
The point of the previous version of that standard, which was debated on this issue fairly extensively above, was that hook implementations should follow the same rules as other function headers. As we had already agreed, don't say what hook_block() is (we can read that on hook_block()'s documentation header), and don't tell us what the standard params are for hook_block() (ditto), say what this particular implementation does that's special. And if there isn't anything special, which may occasionally be the case, maybe we should add to the standard that was reverted that a short form is:
Implements hook_menu().
(note the S on implements, in accordance with current doc standards)
And just as a note, don't we have a policy about debating issues in the issue queue and not on IRC? It nearly made me blow my top yesterday when I realized that doc had been edited without opening this issue back up for discussion. The revision log pointed to this issue, and it should have been discussed here rather than silently edited.
Comment #33
drewish commentedjhodgdon, in hind sight i should have left a comment here but you changes seemed far beyond what had been discussed. as for IRC morbus had simply asked me about my revision.
Comment #34
stella commentedSo can we make the standard for hook implementations be:
If we can agree on that, I don't mind whipping up another patch to fix all of the existing comments in core.
Comment #35
webchickWell, I think we can definitely agree on that. I just think we were trying to take things a step further, and create consistency throughout all documentation, and also potentially make it easier for api.drupal.org to generate lists of hook implementations, since the "references" link doesn't do anything right now on hook_xxx.
But fixing the annoying "Implement" -> "Implements" issue before code freeze would be dramatically awesome, and I guess that one won't be as contentious.
Comment #36
morbus iff@drewish: to be fair, what you reverted is nearly exactly what was posted in comment #14, to which no one naysayed against. But, equally fairly, mentally I skipped over the ramifications of #14 too (I was originally referred to this issue because of the evil evil Druplicon bot telling everyone lies, purportedly, and that's all I was "seeing" and comprehending in this issue.)
Comment #37
morbus iff@jhodgson, for your benefit, reposted without permission:
And then I wrote my comment, above. There was no discussion *prior* to the revert.
Comment #38
morbus iffYes and no. It's a slippery slope. If I have 15 menu items, I'm not going to write a doc for my hook_menu that describes each one, because each one is self-documenting, with its #title and #description and #page_callback. Enforcing _too much documentation_ means one thing: that the documentation is going to go outta date, and I'd much rather have *no* documentation than *incorrect* documentation. As above, I feel the same about hook_block: hook_block is _usually_ a router function, like hook_menu and hook_theme. They primarily serve only to give back a list of *other places to go* (i.e., block functions for 'content', menu functions for 'page callback', template files or function for hook_theme). Documenting them, in the way described in #14 (which I should have read and comprehended and argued against long ago, definitely) would be bad, in my opinion.
The same can be said about the difference between hook_form_alter (a general function that could modify more than one form), and hook_form_FORMID_alter(). In hook_form_alter()'s case, the documentation should be as *close to the code as possible* - I would hate to have a massive ten-form modifying function, hundreds of lines long, and have to go back and forth between the header docs and the actual place in the code they document (or, worse, have duplicate documentation in both places). Compare that to hook_form_FORMID_alter, which affects only one thing, and I'd agree: the documentation should go into the header.
Comment #39
webchickHm. Morbus makes a good point in #38 which supports the simple "Implement[s] hook_foo()." standard we have now.
There's nothing that stops people from documenting particularly tweaky instances of hooks by expanding the PHPDoc:
But in probably half of the hooks, the code is indeed fairly self-explanatory with a quick scan since they're merely registering permissions|menu items|theme functions|etc.
Comment #40
stella commentedhere's a patch that changes core to use "Implements hook_foo()."
Comment #41
sunwell, that was exactly my point in #472642-17: Remove "implementation of" nominalizations from Docblocks. Comments on that issue are closed for whatever reason (which is another indicator for another, monster FAIL).
Comment #42
webchickMarking needs review so test bot picks it up.
Comment #43
webchickAw shoot. Needs to be in the Drupal project as well.
Comment #45
stella commentedpatch re-roll
Comment #46
jhodgdonOK.
I at least added an "s" in http://drupal.org/node/1354 for the standard header.
Comment #47
dale42Found one instance where patch is modifying a header's full description, not simply the 1 line description:
This is the text being changed:
This not only reads badly, as I read the discussion it's not the intent of this patch.
All the other changes are fine.
Comment #48
stella commentedFixed.
Comment #50
stella commentedPatch re-roll
Comment #51
dale42Diff code that I think creates new files slipped in at line 4560. File names:
- modules/simpletest/tests/simpletest_test.info, and
- modules/simpletest/tests/simpletest_test.module
Not sure if this is a problem, but saw six instances of: \ No newline at end of file
The patch removes then re-adds the last line. e.g.:
- */
\ No newline at end of file
+ */
Comment #52
webchickBtw, I can't really see myself committing this until after code freeze since it'll cause massive patch breakage. So you can probably hold off mass re-rolls until Paris. But let's make it one of the first patches we commit after that, OK?
Comment #54
jhodgdonWe need a new patch for this, basically to change
* Implement hook_foo().
to
* Implements hook_foo().
I'll create one. Since we're really in code freeze now, it should (hopefully) be able to be applied without too much consequence?
Comment #55
webchickYep, I will happily commit this as soon as it's ready.
Comment #56
jhodgdonHere's a patch that fixes these (thanks to a little Perl script, and then a few manual changes).
Comment #57
jhodgdonComment #58
sunPerl? Who needs perl for that?
;)
Comment #59
jhodgdonIf all that you did is that simple script, your patch didn't find everything mine did. For one thing, you missed the .install and .profile files. For another thing, my patch includes some manual fixes that the script missed (I did a full search of the source code afterwards, combed it, etc.
So I think my patch is more complete...
Comment #60
sunRight, plus .profile and .install.
Based on the filesize, I'd say that some instances were missing earlier.
Comment #61
jhodgdonYour patch still misses a couple of manual fixes I did in my patch. e.g. line 273 in file.inc. Haven't done a comprehensive survey to find other spots.
Do you have something against my patch in #56? I believe that it applies cleanly and fix the problem comprehensively...
Comment #62
jhodgdonSorry, that was line 273 in modules/simpletest/tests/file_test.module that was missed by your patch.
Comment #63
sunoh, thanks! Then we even have more :)
Could be done in one pass, but splitted for clarity.
Ideally though, I'd prefer to defer this until D7 string freeze, because there are still quite some patches in the queue that would break due to this change.
Comment #64
sunFor later reference:
Comment #65
jhodgdonFYI - I brought this up now because webchick asked me to, in conjunction with another issue.
That aside, I gave your latest patch (#63) a thorough read-through.
Line 273 in modules/simpletest/tests/file_test.module is still not caught (I think that one has 2 spaces between * and Implement).
There are also several places where your approach falls down or manual fixes are needed to bring doc headers into compliance:
From modules/contact/contact.module:
From modules/field/modules/list/list.module:
From modules/menu/menu.module:
From modules/node/node.module:
From modules/simpletest/tests/database_test.module:
From modules/system/system.module:
From modules/toolbar/toolbar.install:
From modules/user/user.module:
Comment #66
sunYes, that's why I posted the more fail-safe command in #64.
Comment #67
jhodgdonOK, then please propose another patch and I will review it.
Comment #68
jhodgdonI don't have sed available on the box where I have Perl available, and that is why I used Perl to generate my patch. But you can't probably just use Perl or sed to generate a patch. You need to take a look at the results, make sure they make sense, and do some hand-editing. Your revised script is not going to fix those errors where a blank line is needed between
and the rest of the comment.
sun -- you seem to want to take this over. Please do so!
Comment #69
sunWe should not squeeze further changes/fixes into this patch. If there is no new line, then there is none. Such fixes need to go into separate issues.
As mentioned before, I don't think it's a good idea to commit a patch like this now. We have merely ~2 weeks left (was it 11/15 or 12/01 again?) for Performance and UX patches, so I'm actually strongly against committing this now.
Comment #70
webchickIMO, it's "API-changeish" since it affects people porting their modules. I'd prefer it get committed sooner than later, since I'm sure we already have a mess out there of Implementation/Implement in D7 contrib. Another 3-4 weeks won't improve things.
Comment #71
jhodgdonOK, sun : If webdries agrees, and if you can run your revised script and make a new patch that doesn't break existing doc, I won't stand in the way of it being applied, just because it doesn't fix the other issues. But normally, patches don't get applied for doc fixes unless they leave the doc in an "up to standards" state for the function headers they affect.
But the latest patch (#63) breaks some existing doc and needs a fix.
Comment #72
jhodgdonNew patch sun?
Alternatively, we can go back to reviewing my proposed (and hand-fixed) patch in #56. Re-attached here for convenience, in case Sun doesn't want to generate a patch that doesn't break existing doc.
Comment #73
jhodgdonComment #75
jhodgdonHere's a re-roll of the patch in #72, with an additional few fixes.
Comment #78
jhodgdonLooks like the patch needs a re-roll again. If that isn't too redundant. I'll take care of it tomorrow AM.
Comment #79
jhodgdonSorry, unintended status change.
Comment #80
jhodgdonHere is yet another re-roll of this patch.
Comment #83
jhodgdonYet another reroll of this huge patch, with more manual fixes.
Comment #84
dries commentedAlright, committed the monster! Thanks all.