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

Larry Garfield larry at garfieldtech.com
Sun Jun 10 16:27:17 UTC 2007


On Sunday 10 June 2007, Angela Byron wrote:

> > It also makes it impossible to definitively extract the providing
> > module from
> > an arbitrary function name, because you don't know if you should
> > break on the
> > first or second underscore to get the module name.  That's a
> > problem that I
> > ran into with the menu-split patch in some iterations.  Sharing a
> > namespace
> > between modules and hook names is nasty and prevents a lot of useful
> > introspection.
>
> Why can't you just do:
>
> <?php
> $list = module_list();
> foreach ($list as $module) {
>    // Check for existence of function or whatever you're doing.
>    if (module_implements($module .'_func') {
>      ...
>    }
> }
> ?>

I ran into this issue in the context of "which file do we need to include so 
that this function becomes available".  The file was module-dependent.  The 
function then did not exist yet, so module_implements() and function_exists() 
won't work.  

Checking all possible permutations of the module/function can get expensive, 
too.  And then there's namespace collisions.  Take for example og and 
og_vocab.  How can core tell whether og_vocab_foo() is the vocab_foo() 
function of og or the foo() function of og_vocab?  I rejected including or 
trying to include the various files it could be in out of hand as way too 
inefficient.  "Guess and check" is not a solution.

> Relying on the module name to NOT have underscores in it seems
> brittle and error-prone to me. There are underscores-o-plenty in
> http://cvs.drupal.org/viewcvs/drupal/contributions/modules/,
> regardless of what we actually decide the standard should be. :) If
> that means we need to make our utility functions more intelligent,
> then we should probably do that.

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

-- 
Larry Garfield			AIM: LOLG42
larry at garfieldtech.com		ICQ: 6817012

"If nature has made any one thing less susceptible than all others of 
exclusive property, it is the action of the thinking power called an idea, 
which an individual may exclusively possess as long as he keeps it to 
himself; but the moment it is divulged, it forces itself into the possession 
of every one, and the receiver cannot dispossess himself of it."  -- Thomas 
Jefferson


More information about the development mailing list