Calling method by name.
Robert Jacques
sandford at jhu.edu
Mon Feb 7 20:54:13 PST 2011
On Sat, 05 Feb 2011 13:14:42 -0500, Jacob Carlborg <doob at me.com> wrote:
> On 2011-02-04 05:07, Jonathan M Davis wrote:
[snip]
>> Most of the good examples of runtime reflection that I'm aware of
>> require user-
>> defined attributes. But there are libraries in Java (and presumably C#)
>> that do
>> stuff like allow you to mark your classes with certain attributes
>> indicating what
>> type of XML elements that they should be, and then another library
>> which knows
>> _nothing_ about your classes is able to serialize them to and from XML.
>> Another
>> example would be Hibernate, which does the same sort of stuff only it
>> deals with
>> talking to databases. Full-on runtime reflection combined with
>> user-defined
>> attributes can do some powerful stuff. However, I do think that runtime
>> reflection
>> without user-defined attributes doesn't tend to be anywhere near as
>> useful. To
>> really get that sort of stuff working, we'd need D to properly support
>> both user-
>> defined attributes and runtime reflection. Both are future
>> possibilities but
>> obviously aren't happening any time soon.
>>
>> - Jonathan M Davis
>
> Ruby seems to get along without any kind of attributes/annotations. But
> on the other hand you can call a method in a class declaration and this
> will behave much the same as a attribute.
>
> ActiveRecord in Rails is a good example of runtime reflection. Also the
> Ruby XML library "builder" is a good example of runtime reflection.
> Maybe not acutally runtime reflection but is uses the "method_missing"
> method, equivalent to the "opDispatch" method in D, heavily.
>
> http://builder.rubyforge.org/
>
I'm still reading up on Ruby, but so far, there are two major difference
between serialization in Ruby and in D. First, Ruby isn't a systems
programming language with pointers/unions/etc, so serializing all members
of a class is generally okay in Ruby but isn't in D. This is the major
advantage of annotations: its a fast, simple way of declaring what should
and shouldn't be serialized. Second, Ruby's support for serialization
creates a back door around its variable protection annotations (i.e.
private,package,protected,public). Now, Ruby doesn't actually have user
defined annotations as far as I can tell, but methods are always public
and variables are always private. I don't believe that a reflection system
should bypass encapsulation. The advantage of annotations is that they
allow you to declare programmer intent and possibly separate APIs (ala
const(T)) for special purposes.
More information about the Digitalmars-d
mailing list