A follow up for #2304909: Relax requirement for @file when using OO Class or Interface per file.
Problem/Motivation
A considerable portion of non OO files has useless @file comment.
Just a few examples:
- aggregator.install and a few other install files
-
/** * @file * Install, update and uninstall functions for the aggregator module. */This comment is confusing because there are no any install, update or uninstall functions in that file.
- ban.module and a few other module files
-
/** * @file * Allows to ban individual IP addresses. */Also confusing because the file actually does not contain any code directly related to the statement. It's just an implementation of hook_help(). If the comment covers all module functionality it would be probably better to change the directive from @file to @module or something else. In any case this would duplicate the module description located in the info.yml file.
/**
* @file
* Miscellaneous functions.
*/
Not functions but just one function. The comment can be changed to Contains drupal_rebuild() which also has no value as was discovered in the related issue.
Proposed change
Either make the @file comment optional or change the comment pattern for *.module and *.install files.
Comments
Comment #2
chi commentedA workaround for custom projects.
Comment #3
pfrenssenI agree that for seasoned Drupal developers these docblocks are redundant, but it still makes sense for junior developers, or developers coming from other platforms to provide context. I can imagine a Symfony developer that is doing a Drupal 8 project being confused by these weird ".module" and ".install" file extensions. It are exactly these files that contain our odd hook-based drupalisms, and a single line of documentation goes a long way to inform people what this is all about.
The examples you provide are noteworthy. I don't mind the standard pattern used for
aggregator.install, butban.moduleshould be better along the lines ofAnd "Miscellaneous functions" is just sad.
Comment #4
chi commentedComment #5
donquixote commented@pfrenssen Good point about information for newcomers!
I wonder though if this is really worth the trouble. It is a trade-off.
I see similar arguments apply here like for "convention over configuration".
A lot of organisations will ask their developers to follow the standards from https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... to the letter for custom code.
It could be useful to suggest that organisations or contrib developers can opt out of specific rules.
Of course no organisation is forced to follow anything, but it can be suggested which rules are absolutely recommended and which could be considered optional.
The main argument provided for @file docs is that they will be read by the API module. Typically this is irrelevant for custom code.
On the other hand, @param and @return docs can be read by an IDE and are very useful.
Comment #6
donquixote commented@pfrenssen to add to my previous comment.
This is a nice intention, but it is not what I see being done in custom modules for real-world website projects.
Instead, I see people run phpcbf to insert stub comments, and then (if we are lucky) these stubs are filled out with random meaningless phrases.
All of this is done for compliance, not to make the code more readable.
For developers who care more, there is a risk of losing valuable time, billed to the client or employer, to bikeshed which phrase to use in this doc block.
(My personal philosophy is "If you don't have something meaningful to say, don't say it.". But this goes beyond this issue.)
Another risk is that developers are too specific in the @file doc, e.g.
A doc phrase like this either will get outdated very soon, or it has to be updated whenever something new is added to the file.
Something more generic like "This is the place for hook_menu(), hook_block_info() or other hooks." can avoid this. But does every developer you add to a project know this?
Another anti-pattern is to use the @file doc to explain what the module does.
E.g. in D7 node.module:
This text has nothing to do with the *.module file specifically, it rather belongs into a README, or into the description in the *.info file.
Or optionally it could go into a section into the @file doc, but below the top line which should document the role of this specific file, not the role of the module itself.
The goal you mention could be achieved with a standardized phrase, e.g.
Such default docs could be inserted automatically by a tool like phpcbf, which would reduce the risk that developers insert useless comments only for the sake of compliance.
Still this is not a guarantee that developers will use these standardized phrases, or that they will insert anything useful at all instead of meaningless or even misleading text.
Comment #7
quietone commentedComment #8
borisson_With the current way core seems to be going in trying to remove most of these files, by making hooks annotation based, it looks like the argument is start to lose value?
Comment #9
quietone commentedThere are only 86 .module files left, so this is mostly about .install files. I am not a fan of the extra documentation in the example for .install in #6. If we wanted to do something like that I would rather it just be @see to other API documentation.