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

Angela Byron drupal-devel at webchick.net
Sun Jun 10 12:17:24 UTC 2007


New thread, so we don't swamp poor Jakob's. :) Let's get consensus  
here and then update the coding standards.

On 9-Jun-07, at 8:29 PM, Larry Garfield wrote:

> On Saturday 09 June 2007, Angela Byron wrote:
>> On 9-Jun-07, at 1:36 PM, Doug Green wrote:
>>> Angie,
>>>
>>> Why is version_control preferred over versioncontrol?
>>
>> For legibility. It's consistent with our variable naming convention,
>> and separating the individual words help non-English speakers who can
>> babelfish individual words to figure out what a particular thing is
>> doing.
>>
>>>   I thought we only
>>> used the underscores when the module was extending another module.
>>> And I
>>> thought we had problems with hook functions related to underscores,
>>> or is
>>> the problem only related to hook's with underscores?
>>
>> I know of no such problems. The only thing I can think that would
>> cause a problem is if you named a function something like
>> my_module_insert and Drupal mistook it for a node insert hook when it
>> was just a helper function or something. But mymodule_insert would
>> have exactly the same problem.
>
> 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') {
     ...
   }
}
?>

The module name and the prefix will always match, except in the case  
where an underscore prefixes a function name, but again, that problem  
surfaces for both _mymodule_func and mymodule_func.

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.

-Angie



More information about the development mailing list