[development] Rename *_load and friends
James Walker
walkah at walkah.net
Sat Jan 6 16:08:08 UTC 2007
On 1/6/07 1:22 AM, Karoly Negyesi wrote:
> Hi,
>
> We have had a discussion about this already under a different subject.
>
> My opinion here is that hook_foo is something that gets implemented by N
> modules and at call time these are called, one after the other.
> hook_menu , hook_form_alter etc etc Note that 'hook' is always replaced
> by the module name.
>
> Despite hook_load is called a hook, it's a different animal: at call
> time, only one implementation is called. Not to mention that since we
> have a node information hook, 'hook' is not necessarily replaced by the
> module name.
>
> Larry Garfield suggested calling these method_load, method_view and so
> on. This I find a good idea and now would like to get opinions on this
> name.
I'm not sure I know why they need different names, and I'm not sure
where you draw the line. While I absolutely am +1 for keeping hook_load,
etc in addition to hook_nodeapi - I don't know that calling some
method_* vs. hook_* really brings all that much clarity.
We use "hooks" for *lots* of different things - sometimes pass by
reference sometimes by value, with all kinds of different expected
return values and behaviours. I don't know how much this single
distinction helps. Not to mention, I think we can disappear into a dark
hole arguing the semantics (i.e. in OO & AO programming, they're all
just called "methods" anyway).
The nice thing about the 'hook' name (whether invented or otherwise) is
it's easy to teach new developers how hooks relate to the code their
looking at, and further that when you see module_foo() you can find full
documentation on api.drupal.org by searching for hook_foo.
I've done several training sessions now and have not run into a whole
lot of confusion from the naming. Fact is, they're not really "methods"
- reusing a name with a common, different meaning for most developers
may well just add confusion.
that's my $0.02 anyway.
--
James Walker :: http://walkah.net/ :: xmpp:walkah at walkah.net
More information about the development
mailing list