[development] the time of $op is over?

Larry Garfield larry at garfieldtech.com
Tue May 13 04:40:24 UTC 2008


On Friday 09 May 2008, Daniel F. Kudwien wrote:
> > Regardless I think it's a logical progression instead of
> > everyone writing a switch statement to parse out which $op
> > it is everytime.
>
> I agree, but I guess this will make debugging a bit harder.

On the contrary, smaller, more targeted functions should make debugging 
easier, as well as unit testing easier.  You then have more bite-sized code 
snippets that have fewer possible states and fewer internal logical branches, 
hence they're more deterministic and easier to debug.  You can also move them 
about to different files if needed, which helps the registry.  

The only downside is if you need to share data from one op to another (say 
from submit to validate to update).  Right now that is trivially easy with a 
static variable.  If they're in separate functions, you need a collector 
function of some kind or a variable_set(), or a central static variable store 
(chx submitted a patch for that which I've not looked into yet, but I think 
that should be OO rather than purely procedural to make it more modular, for 
which he will probably try to smack me), or some other mechanism.  (Global 
variables for that are a design flaw; please don't try it.)  It's a solvable 
problem.

Similarly, most form_alter implementations can easily be made into 
form_$form_id_alter functions, which is a nice simplification and a 
registry-help for the same reasons.  

I have plans percolating in the back of my head to modernize hook_block, took, 
to make it more menu-ish in structure and break it out into multiple 
functions.  That's not something I'm going to spend any code time on until 
after the database work is completed, though.

I have an irrational hatred of switch statements, so eliminating hooks that 
are nothing but nested switch statements half the time gets a big +1 from 
me. :-)

-- 
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