[Nitro] Og Revisted

Michael Fellinger manveru at weez.co.jp
Thu Feb 9 23:14:55 EST 2006

Hey Trans,

Well, changing enchanting is really a big deal.
I have got used to the magic nitro does - on the other hand it might be better 
to make everything a bit more stable - it's an opportunity to get back to 
attr_accessor and making classes more generic and useable for other 
ruby-programs to use.
The ideal is, as always, a compromise between both.
I understand that enchanting has some real drawbacks in performance and also 
the endless checking if the classes are enchantet already influenced the 
readability of the og-code in a bad way.
Still it is one thing less to think about while working with og, you just make 
a class - restart and voila, there you go.
So, how about following:

def require_og_models(*models)
  snapshot_pre = []
  snapshot_post = []
  ObjectSpace.each_object{|o| snapshot_pre << o}
  models.each{|m| require(m)}
  ObjectSpace.each_object{|o| snapshot_post << o}

require_og_models "model.rb"

i think this is a really elegant way to handle it. We could check the 
objectspace before and afterwards - enchanting the classes that came in after 
the wrap of require.
I'm not sure everybody likes it, but it looks like this could be a way to do 
everything more elegant (code in og, code in the app), getting rid of 
'property' (an issue for some people who use it with glib), and getting a 
real performance-boost as well.
This is of course only some random code - i don't think it's as easy as that - 
but it would be nice if it was :)
additional this gives us the option to manually enchant them, using

require 'model.rb'
enchant(Foo, Bar, FooBar)

wich makes a nice reuse of the (not yet existent) enchant-method...

Now, please click on your reply-buttons and critizise that idea down to 
something that really works - this was only an idea i had :)


Am Friday 10 February 2006 11:18 schrieb TRANS:
> I'd like work on improving Og according to some of the ideas here:
>   http://www.nitrohq.com/view/OgRevisited
> The first part is to change the way a class gets enchanted
> ("ogified"). Right now a class in _usually_ enchanted when the
> #property method is used. There are a few draw backs to this. Firstly,
> it is inefficent b/c every time the property method is called it has
> to first check to see if the class is already enchanted or not. Also,
> it's not 100% consistant because some people have reported cases when
> a class needs to be enchanted though the #property method hasn't been
> used. And though it's nice when things seem automatic, in this case
> being explict about which class are enchanted is a much better thing,
> making it easier to maintain the code. Also it will greatly reduce
> some complexity in parts of the Og code and improve run times a bit.
> So what do others think? Also, what alternatives, modifications, or
> other suggestions with regard to this (the Setup section on the wiki
> page) does anyone have?
> T.
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general

More information about the Nitro-general mailing list