[development] Module Builder Module 1.0
larry at garfieldtech.com
Wed Feb 22 04:40:13 UTC 2006
On Tuesday 21 February 2006 07:26, Angie Byron wrote:
> At DrupalCon, a few of us had talked about how handy it would be to have a
> module that automatically generated "scaffolding" for modules, both to help
> new developers as well as to speed up the process of creating custom
> modules for Drupal veterans.
> As a result of a major bout of insomnia, I am pleased to announce that
> Module Builder Module 1.0 has been committed to CVS, and even pretty much
> works! ;) You can check it out at:
OK, I've not actually looked at it yet, so I can't comment on how
good/late-night the code is, but my knee-jerk reaction is that I don't like
code generation in the first place. If the code is sufficiently boilerplate
that it can be auto-generated, then it's sufficiently boilerplate that it
should be written as a single routine and called with paramters. That's the
logic behind functions and variables. :-)
As a for-instance:
hook_load(), hook_insert(), and hook_update() are horribly redundant. All
three do the same thing in almost any node. They select/insert/delete fields
from a table, using almost the same code. Sometimes there will be an extra
table to manipulate, but there's still almost always a basic node++ table.
And the fields have to be specified in all of them. Ick!
The solution, however, isn't to have something that auto-generates those
functions. It's to let the module define the table and fields once and then
let node.module handle the basic S-I-D. Save those hooks for stuff that's
actually interesting, and reduce the amount of code, too.
I'm thinking something like:
return array('nodenametable' => array('field1', 'field2', 'field3'));
That would also allow node_load() to return an "empty node" of the correct
type, which would help with E_ALL compliance.
(Yes, this is something I've been thinking about for some time, but have been
holding back on actually trying to implement because I didn't want to
introduce a change of that size when we've been "almost ready to get 4.7 out
the door" since, uh, November. Hi, Ber! <g> I actually did something very
similar to this at work, so I know it can be done.)
So yeah, code generation in general gets a -1 for me in favor of more powerful
and generalized polymorphic code.
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
More information about the development