[development] low hanging fruit for Drupal 6: variable defaults

Earnie Boyd earnie at users.sourceforge.net
Thu May 3 19:05:53 UTC 2007

Quoting Aaron Winborn <aaron at culturefix.org>:

> There are times one might try to access a variable defined by another 
> module, such as variable_get('site_name', 'Drupal'); This would make 
> it easier to avoid having to remember later if that's supposed to be 
> variable_get('site_name', 'drupal'), variable_get('site_name', 
> t('Drupal')), variable_get('site_name', SYSTEM_SITE_NAME_DEFAULT), or 
> whatever. I believe just calling variable_get('site_name') would 
> certainly makes things more standard, and easier to maintain.

And how do you know that 'site_name' is a variable to get?  What 
happens when I variable_get('not_a_saved_variable')?  If the variable 
is public then it needs to be documented so you would know how to get 
it and you would know how to supply it's default value.

With what is being proposed variable_get would need to try to get the 
default value of the variable every time.  Now it is given so that it 
doesn't have to try to guess.  Why do I need variable_get to try to 
waste resources by trying to guess the default when I can give it along 
with the variable?  This wasted resource is system wide and affects 
every module that stores a variable.

> And having a namespace available would be the cherry on top.

Something like 'drupal::drupal_variable' and 'my_module::my_variable' 
might be nice with the default being my_module.


More information about the development mailing list