[Nitro] Serious discussion on Annotaitons - Part II

transfire at gmail.com transfire at gmail.com
Sun Oct 29 07:24:27 EST 2006

I direct you to ruby-talk:202245 in which Ara points out:

i use method_missing too but, in this case, you'd have to provide an
strong argument why an interface like this won't suffice:

   harp:~ > cat a.rb
   class Module
     def ann meth, arg = nil
       @ann ||= {}
       if Hash === arg
         arg ? (@ann[meth] ||= {}).update(arg) : @ann[meth]
         arg ? @ann[meth][arg] : @ann[meth]

   class X
     ann :x, :class => String, :default => 10, :foo => :bar

   X.ann :x, :class   #=> String
   X.ann :x, :default #=> 10
   X.ann :x, :foo     #=> :bar

   X.ann :x           #=> {:class => String, :default => 10, :foo =>

Now this implementatin leaves out some of the needed shortcuts (like
implied class annotation) and it also leaves out the BIG issue of
inheritance, but those can of course can be worked in. The main thing
here is the simplicty of the interface. I realize it's a big change but
I think Ara has a point. The simplicy, uniformity and consistancy has
it's own merits over the elegance of the magic dot notation. Then main
complexity and overheas arises with the addition of two new types of
objects: an 'Annotation' an 'Annotations'.

The other thing to discuss is the need for even one Annotation class to
support class/name storage in the annotation itself. Ie. Should

   X.ann :x           #=> {:class => String, :default => 10, :foo =>


   X.ann :x           #=> #<Annotations(X#x) class=String, default=10,

and maybe also

   X.ann :x, :class   #=> #<Annotation(X#x).class=String>

The later allows the name and class/module of annotation to be stored
inside the annotation itself at the expense of an additional object.
This can be helpful in some cases and other benefits may arise from
having separate class(es), like a extra X.ann(:x).foo notation. But
there are potential issues with this, and I fear the added complexity
might in fact be causing the latest version of annotation.rb not to
work right. The problem being that if we define an annotation in a
module then it gets attacthed to that module and when using it in
inheritance that might cause issues down the inheritance chain
--athough I can't invsion what that might look like at this point, it
may in fact be the problem with current Nitro. In anycase it runs a
greater risk and complication in that regard, but much larger overhead
since every annotation is a new object. So I don't know if it a good
idea. And I suspect something isn't quite right if we need to ask an
annotation what class it belongs to. In such cases I would suggest
passing a Hash instead:

  C.ann a, n
  x = { :class => C, :note => a, :name => n }
  x[:class].ann(x[:note], x[:name])

Or make a Struct for the paricular case.

  Ann = Strunct.new(:class, :note, :name)
  x = Ann.new(C,a,n)
  x.class.ann(x.note, x.name)

And for a quick return to the original argument, using the magic dot
notation here leads to the last lines in the examples to be:





More information about the Nitro-general mailing list