[development] Module naming conventions (was Re: Naming the CVS abstraction module)

Derek Wright drupal at dwwright.net
Sun Jun 10 17:26:08 UTC 2007

On Jun 10, 2007, at 9:27 AM, Larry Garfield wrote:

> Yes, there are lots of modules that do have underscores and lots  
> that don't.
> There is no standard right now; certainly not one that's enforced.   
> Were we
> to start doing so, however, no-underscore is far better as it  
> allows us
> better introspection capabilities.  I personally find it more  
> readable as
> well, but I'm sure others will disagree. :-)

This came up long ago, and one of the best ideas that came out of the  
previous thread (thanks, chx) was to use '__' (2 underscores) to  
separate modules names from hook names.  A few reasons to do so:

1) Renaming all the existing projects with underscores in their names  
is never going to happen.  Aside from the fact that renaming files  
and directories is hard in CVS, there's also the problem of link rot  
for project nodes on d.o, pain-in-the-ass upgrade paths for existing  
sites (entries in {system}, {variables}, etc, etc).

2) Drupal hates CamelCapsToSeparateWords, so we have to use  
underscores_to_separate_words, unless you really expect everyone to  
be able to understand nothingtoseparatewords.

3) If we just say, as of D6, "all hooks will be invoked with 2  
underscores to separate the module name from the hook name", it's a  
rather trivial porting job that could be easily scripted (and  
enforced in the implementation of module_invoke() and  
module_invoke_all(), etc).

4) Helps people differentiate hook implementations from functions  
private to a specific module.

5) A partially followed, non-enforced standard won't actually provide  
better introspection capabilities.  If you're not sure everything is  
following your convention, you can't write code to assume it does.   
module_name__hook() introspection, however, *would* provide better  
introspection, since we could in fact write code (in D6 at least)  
that knows it can trust that.

6) There's already some prior-art for using double-characater  
separators in Drupal development: our branch/tag conventions (DRUPAL- 
VERSION-INFO--PROJECT-PARTS).  This allows us to handle both  
DRUPAL-5--1-0 and DRUPAL-4-7--1-0 and know exactly which digits go  
with what version we need to know.

-Derek (dww)

More information about the development mailing list