Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Is there any rhyme or reason to how module functions are organized, visibly, in the module source code? It would seem to help immediate clarity, for example, if _menu was always near the tippy top (along with _help) - these both introduce the module and declare what URLs you'll be worrying about during your stay with the source. Having consistent placement for at least these two (and, perhaps all _apihooks) would increase the readability of the code (as an example, watchdog.module is the model I'd want to follow, and user.module is the model that should be "fixed").
Comment | File | Size | Author |
---|---|---|---|
#4 | comment_reorg.patch | 35.69 KB | Morbus Iff |
Comments
Comment #1
JonBob CreditAttribution: JonBob commentedI considered such reorganization as part of my recent code standardization pass through core, but decided not to because it would make the already huge patches even more incomprehensible. I'd support such an effort.
I'd propose the following order:
Constants
hook_menu()
hook_help()
hook_perm()
(These three provide a good idea of the module's structure)
Other core hooks
Any node hooks
Any authentication hooks
Public functions exposed by the module
Themeable functions
Private functions
Comment #2
Morbus IffI agree with the proposed order; watchdog.module already matches this (with the latest commit today). I'll give this Issue a few days to percolate, and then start applying the proposal sometime next week. I hope.
Comment #3
Dries CreditAttribution: Dries commentedI support this too (though, it should not be a requirement).
Comment #4
Morbus IffSetting this critical just because it'll break very easily. This is a reorg of the comments.module (nothing added or deleted, just moved around), per the above schema (and mimicking watchdog.module). I'll be working on doxygentation of comment.module next as I learn my way around it.
Comment #5
Dries CreditAttribution: Dries commentedCommitted to HEAD.
Comment #6
JonBob CreditAttribution: JonBob commentedComment #7
matt westgate CreditAttribution: matt westgate commentedIt would be great to have a standardized module structure.
Personally, I would like to see hook_help() come before hook_menu() as I generally read what the module is about before where it is invoked.
Comment #8
JonBob CreditAttribution: JonBob commentedComment #9
Jose Reyero CreditAttribution: Jose Reyero commentedI think the best option would be grouping some functions and then order alphabetically. It is the only easy way to know where every function should go.
I.e.
1. Implemented hooks
2. Module API
3. Any other stuff
Comment #10
bdragon CreditAttribution: bdragon commentedI rather think this is material for the developer guide, that is, if anyone still cares at all about the order of functions anymore...
Comment #11
nielsbom CreditAttribution: nielsbom commentedChanged the component to reflect the new component categorization. See http://drupal.org/node/301443
-nielsbom
Comment #12
jbrauer CreditAttribution: jbrauer commentedThis seems to have lost steam. It seems like a good idea and is something that should be looked at for the coding standards cleanup. Closing for now subject to being reopened if there's a desire by somebody to make it happen.