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").

CommentFileSizeAuthor
#4 comment_reorg.patch35.69 KBMorbus Iff
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JonBob’s picture

I 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

Morbus Iff’s picture

I 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.

Dries’s picture

I support this too (though, it should not be a requirement).

Morbus Iff’s picture

Priority: Normal » Critical
FileSize
35.69 KB

Setting 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.

Dries’s picture

Committed to HEAD.

JonBob’s picture

Priority: Critical » Normal
matt westgate’s picture

It 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.

JonBob’s picture

Priority: Normal » Minor
Jose Reyero’s picture

Component: module system » other

I 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

bdragon’s picture

Project: Drupal core » Documentation
Version: x.y.z »
Component: other » Developer Guide

I rather think this is material for the developer guide, that is, if anyone still cares at all about the order of functions anymore...

nielsbom’s picture

Component: Developer Guide » Placement and navigation

Changed the component to reflect the new component categorization. See http://drupal.org/node/301443
-nielsbom

jbrauer’s picture

Component: Placement and navigation » Correction/Clarification
Status: Active » Fixed

This 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.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.