Hi --

On Wed, 26 Oct 2005, Duane Johnson wrote:

> I was intrigued by one of Matz's "Wild and Crazy Ideas" at RubyConf--the 
> inclusion of meta data in the comments section before a method definition.
>
> This got me thinking about the need for metadata and Ruby's fabulous 
> introspective capabilities and I wondered if it might be better to have a 
> governing "metamethod" for each method.  Actually, more like accessor 
> metamethods.  These metamethods would be in charge of setting or getting 
> key/value pairs describing things about the method it is associated with:
>
> # Returns double the input
> def double(i)
>   i * 2
> end
>
> meta :double, :require => 'i.is_a? Fixnum'

It seems awkward (even leaving duck-typing issues aside :-) to have a
constraint like that stored in a kind of eval string, rather than just
executed as part of the method.  I'm not sure what's gained.

> meta :double, :comments
> => 'Returns double the input'

In some ways I prefer going in the other direction -- that is, letting
the method be its own comment as much as possible.  I can't help
thinking that part of the beauty of the language is that

   def double(i)
     i * 2
   end

is so complete, and so completely transparent.  I'd be loathe to add
even one line of comment to it, and even more so to add a separate
method call ("meta") to store comments.

I understand (a) that this was just an example, and (b) that some
people prefer to have comments for every method, no matter how
self-documenting it is.  I don't; I prefer the source code to be as
clean as possible (though no cleaner :-)


David

-- 
David A. Black
dblack / wobblini.net