[Nitro] Simpler configuration method?

Jonathan Buch john at oxyliquit.de
Sun Feb 4 08:02:51 EST 2007


Hi,

> It is amusing that people consider this unacceptable:
>
> $conf_template_root_dir = '...'
>
> but this acceptable:
>
> Conf["Template.root_dir"] = '...'
> or
> Conf[:Template][:root_dir] = '...' <--- this is curently used,
> Template.root_dir is syntax sugar for Conf[:Template][:root_dir] atm.
>
> as they are exactly the same thing...
[snipped rest]

Those three things are different, in the sense where they are in memory
and how they are accessed.

The $global namespace is used by everything which is _really_ global,
many people can create globals, name clashes may be possible.

The first two are similar in the sense, that there is only a single
namespace, the third make one namespace for one 'configuration area'
and so one doesn't have to take care of that.

dead simple grep, counting current settings (might be off a few):
$ grep -R 'setting :' . | wc -l
      256

irb(main):042:0> global_variables.size
=> 60

Would someone like to put our ~250 current settings into the global
namespace?  I just feel that it 'doesn't belong to us'.

When we want to retain the ability to specify the default inside
a class:

class Template
   Conf[name][:root_dir] ||= '/'
end

Something like that has to be used, and we will still loose the
ability to specify documentation stuff which can be used by a
admin interface...  However, I'd be ok with that one, but:

class Template
   Conf["#{name}_root_dir"] ||= '/'
end

This one would be what George would agree on I guess, I just feel
that it's not as nice, and it still has the problem that it is in
a single namespace.

http://pastie.caboo.se/37807

George and me discussing over this on IRC, there were a few good
points made on either side there.  (I hope it's ok posting this,
George?)

So, if we're gonna touch the Configuration at all, I vote for
the 2 level namespace and Nitro::Conf (not ::Conf).
This doesn't have much overhead (Conf having [] overridden, for
creating them dynamically and returning a new Hash).  It isn't
as visually pleasing as the current .setting style, but ah well.

My take on this, and I'll not back away, as the $global approach
just 'feels' wrong to me.

Comparison:

# current:
## create:
class Template
   setting :root_dir, :default => ''
end
## access:
* Template.root_dir
* Configuration[:Template][:root_dir]
* class Template
     def a
       self.class.root_dir
     end
   end

# 1 level
## create:
class Template
   Conf["#{self.name}_root_dir"] ||= ''
end
## access:
* Conf['Template_root_dir']
* class Template
     def a
       Conf["#{self.name}_root_dir"]
     end
   end


# 2 level
## create:
class Template
   Conf[self.name][:root_dir] ||= ''
end
## access:
* Conf[:Template][:root_dir]
* class Template
     def a
       Conf[self.name][:root_dir]
     end
   end

Did I miss something?

Jo

-- 
Feel the love
http://pinkjuice.com/pics/ruby.png


More information about the Nitro-general mailing list