| Thread overview | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 29, 2008 Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
I have searched through the pdf documentation bit did not find a full explanation of RTTI facilities in D. The reason I ask about this is that it appears there is a 3rd party reflection facility but I do not see the documentation in D that explains if and how reflection works in D. Does it exist in D ? Is there documentation for it ? | ||||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Edward Diener wrote: > I have searched through the pdf documentation bit did not find a full > explanation of RTTI facilities in D. The reason I ask about this is that > it appears there is a 3rd party reflection facility but I do not see the > documentation in D that explains if and how reflection works in D. Does > it exist in D ? Is there documentation for it ? > D 2.0 is an experimental branch which supports compile time reflection. It's documented here: http://digitalmars.com/d/2.0/traits.html | |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Xinok | Xinok wrote:
> Edward Diener wrote:
>> I have searched through the pdf documentation bit did not find a full
>> explanation of RTTI facilities in D. The reason I ask about this is that
>> it appears there is a 3rd party reflection facility but I do not see the
>> documentation in D that explains if and how reflection works in D. Does
>> it exist in D ? Is there documentation for it ?
>>
> D 2.0 is an experimental branch which supports compile time reflection. It's documented here:
> http://digitalmars.com/d/2.0/traits.html
That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge.
Is there any run-time reflection in D ? If not I would like to make a strong argument for it on this NG and then let others comment on it or at least have Walter see it. I realize implementing run-time reflection in any language is exceedingly difficult, but my argument would make a case for its importance in D if it could be done.
| |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | "Edward Diener" <eddielee_no_spam_here@tropicsoft.com> wrote in message news:fnm1qm$1tiu$1@digitalmars.com... > Xinok wrote: >> Edward Diener wrote: >>> I have searched through the pdf documentation bit did not find a full explanation of RTTI facilities in D. The reason I ask about this is that it appears there is a 3rd party reflection facility but I do not see the documentation in D that explains if and how reflection works in D. Does it exist in D ? Is there documentation for it ? >>> >> D 2.0 is an experimental branch which supports compile time reflection. >> It's documented here: >> http://digitalmars.com/d/2.0/traits.html > > That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge. > > Is there any run-time reflection in D ? If not I would like to make a strong argument for it on this NG and then let others comment on it or at least have Walter see it. I realize implementing run-time reflection in any language is exceedingly difficult, but my argument would make a case for its importance in D if it could be done. There is flectioned (http://flectioned.kuehne.cn/), likely the library you mentioned. The D compiler by default inserts some RTTI information, but it's not complete by any means. The nice thing about compile-time reflection, though, is that you can use it to _create_ runtime reflection from within the language, rather than relying on a third-party tool to do so. This offers the possibility of providing runtime reflection, which is a feature not everyone needs, as part of the standard library rather than as a built-in feature of the language. | |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Edward Diener wrote:
> Xinok wrote:
>> Edward Diener wrote:
>>> I have searched through the pdf documentation bit did not find a full
>>> explanation of RTTI facilities in D. The reason I ask about this is that
>>> it appears there is a 3rd party reflection facility but I do not see the
>>> documentation in D that explains if and how reflection works in D. Does
>>> it exist in D ? Is there documentation for it ?
>>>
>> D 2.0 is an experimental branch which supports compile time reflection. It's documented here:
>> http://digitalmars.com/d/2.0/traits.html
>
> That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge.
>
> Is there any run-time reflection in D ? If not I would like to make a strong argument for it on this NG and then let others comment on it or at least have Walter see it. I realize implementing run-time reflection in any language is exceedingly difficult, but my argument would make a case for its importance in D if it could be done.
Runtime reflection is quite weak in D. I was considering providing some facility for it for one of my projects, but that turned out not to be necessary, so I decided against it.
The main problem is getting all types. You can easily register a type for RTTI with a mixin, but I'm not sure how else to do it. I thought I saw a trait to do it (__traits(derivedTypes, Object)), but I was mistaken, and such a thing would be pretty much impossible. In my situation, I didn't need nearly so much information; the trouble was passing type information to arbitrary entities.
I browsed the Flectioned source once to see how it acquired runtime type information, but it scared me, and I haven't looked at it since.
| |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | Edward Diener wrote:
> Xinok wrote:
>> Edward Diener wrote:
>>> I have searched through the pdf documentation bit did not find a full
>>> explanation of RTTI facilities in D. The reason I ask about this is that
>>> it appears there is a 3rd party reflection facility but I do not see the
>>> documentation in D that explains if and how reflection works in D. Does
>>> it exist in D ? Is there documentation for it ?
>>>
>> D 2.0 is an experimental branch which supports compile time reflection. It's documented here:
>> http://digitalmars.com/d/2.0/traits.html
>
> That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge.
Also, you can use the classinfo for a type to create new instances of that type, provided that type has a default constructor (one that can be called with no arguments). That doesn't let you do a whole lot, I realize, but it's better than nothing.
| |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote: > "Edward Diener" <eddielee_no_spam_here@tropicsoft.com> wrote in message news:fnm1qm$1tiu$1@digitalmars.com... >> Xinok wrote: >>> Edward Diener wrote: >>>> I have searched through the pdf documentation bit did not find a full >>>> explanation of RTTI facilities in D. The reason I ask about this is that >>>> it appears there is a 3rd party reflection facility but I do not see the >>>> documentation in D that explains if and how reflection works in D. Does >>>> it exist in D ? Is there documentation for it ? >>>> >>> D 2.0 is an experimental branch which supports compile time reflection. It's documented here: >>> http://digitalmars.com/d/2.0/traits.html >> That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge. >> >> Is there any run-time reflection in D ? If not I would like to make a strong argument for it on this NG and then let others comment on it or at least have Walter see it. I realize implementing run-time reflection in any language is exceedingly difficult, but my argument would make a case for its importance in D if it could be done. > > There is flectioned (http://flectioned.kuehne.cn/), likely the library you mentioned. The D compiler by default inserts some RTTI information, but it's not complete by any means. Yes, that is the library but I have not looked at it yet myself. Because it mentioned reflection, I assumed that run-time reflection must be available in D in some form. > > The nice thing about compile-time reflection, though, is that you can use it to _create_ runtime reflection from within the language, rather than relying on a third-party tool to do so. This offers the possibility of providing runtime reflection, which is a feature not everyone needs, as part of the standard library rather than as a built-in feature of the language. From the facilities mentioned at http://digitalmars.com/d/2.0/traits.html it is hard to imagine how one can create runtime reflection on unknown types at compile time. If it can indeed be done then it appears to be something that can not be done from the outside by a 3rd party tool since that tool would have to be able to be compiled and know about partcular types in advance in order to gather the data it needs. There is no use in the link above for using strings to pass the names of the types that one needs to reflect. So I have to believe there is more to it than the link above explains. Real run-time reflection in D would mean that: 1) One can query for the names of all types in a module given a module name. 2) One can query for all parts of a type given a type name or an object of that type. 3) One can instantiate a type given a type name and exercise that type by calling its methods, getting and setting its properties, triggering its events etc. I think you get the idea. I could go into the major usage of run-time reflection in modern IDE environments but if I just say RAD programming, ala forms, components, and design-time manipulation as in C++ Builder and later in Visual Studio .Net, you can probably extrapolate where I am going with it. I will just add that C++ as a a standard has been adamantly opposed to such ideas, but from this programmer's point of view it will be the way of programming in the future. Without real run-time reflection RAD programming is nearly hopeless. That is the reason why implementing it in D and working toward a RAD programming IDE using D would be a major advantage and selling to using D over and above its additions and possible improvements to C++ IMO. But I do realize how difficult adding run-time reflection may be from the compiler's point of view. | |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | Christopher Wright wrote:
> Edward Diener wrote:
>> Xinok wrote:
>>> Edward Diener wrote:
>>>> I have searched through the pdf documentation bit did not find a full
>>>> explanation of RTTI facilities in D. The reason I ask about this is that
>>>> it appears there is a 3rd party reflection facility but I do not see the
>>>> documentation in D that explains if and how reflection works in D. Does
>>>> it exist in D ? Is there documentation for it ?
>>>>
>>> D 2.0 is an experimental branch which supports compile time reflection. It's documented here:
>>> http://digitalmars.com/d/2.0/traits.html
>>
>> That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge.
>>
>> Is there any run-time reflection in D ? If not I would like to make a strong argument for it on this NG and then let others comment on it or at least have Walter see it. I realize implementing run-time reflection in any language is exceedingly difficult, but my argument would make a case for its importance in D if it could be done.
>
> Runtime reflection is quite weak in D. I was considering providing some facility for it for one of my projects, but that turned out not to be necessary, so I decided against it.
>
> The main problem is getting all types. You can easily register a type for RTTI with a mixin, but I'm not sure how else to do it. I thought I saw a trait to do it (__traits(derivedTypes, Object)), but I was mistaken, and such a thing would be pretty much impossible. In my situation, I didn't need nearly so much information; the trouble was passing type information to arbitrary entities.
>
> I browsed the Flectioned source once to see how it acquired runtime type information, but it scared me, and I haven't looked at it since.
I will take a look at Flectioned and perhaps the things it can do will surprise me. But I have the sneaking suspicion that I am not cognizant of all there is to know about RTTI in D as yet.
| |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Christopher Wright | Christopher Wright wrote:
> Edward Diener wrote:
>> Xinok wrote:
>>> Edward Diener wrote:
>>>> I have searched through the pdf documentation bit did not find a full
>>>> explanation of RTTI facilities in D. The reason I ask about this is that
>>>> it appears there is a 3rd party reflection facility but I do not see the
>>>> documentation in D that explains if and how reflection works in D. Does
>>>> it exist in D ? Is there documentation for it ?
>>>>
>>> D 2.0 is an experimental branch which supports compile time reflection. It's documented here:
>>> http://digitalmars.com/d/2.0/traits.html
>>
>> That is compile-time reflection, which is useful for creating code but not for instantiating objects at run-time and finding out about them. It is also very limiting in the form presented as one can not instantiate objects in the compile time constructs based on the information returned, but just react in a way to the information found. I am not putting down the effort as it more than duplicates and is more effective than the Boost traits library, since it is based on compiler knowledge.
>
> Also, you can use the classinfo for a type to create new instances of that type, provided that type has a default constructor (one that can be called with no arguments). That doesn't let you do a whole lot, I realize, but it's better than nothing.
I do not see any information in the docs about classinfo. Perhaps these things do not exist in D 1.0 and are there somewhere in D 2.0 . But without real docs for D 2.0 I will wait until there is some.
| |||
January 29, 2008 Re: Newbie initial comments on D language - RTTI and run-time reflection | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Edward Diener | "Edward Diener" <eddielee_no_spam_here@tropicsoft.com> wrote in message news:fnmaec$2j4f$1@digitalmars.com... > > From the facilities mentioned at http://digitalmars.com/d/2.0/traits.html it is hard to imagine how one can create runtime reflection on unknown types at compile time. By using compile-time reflection primitives to build up metadata structures at compile time which are embedded in the app/library and which can then be used to query information about modules, the types and functions in them, etc. > If it can indeed be done then it appears to be something that can not be done from the outside by a 3rd party tool since that tool would have to be able to be compiled and know about partcular types in advance in order to gather the data it needs. No, it'd be done by using a tool that would parse D code into an AST, find the declarations in it, and similarly to above, generate the same kind of metadata. > I could go into the major usage of run-time reflection in modern IDE environments but if I just say RAD programming, ala forms, components, and design-time manipulation as in C++ Builder and later in Visual Studio .Net, you can probably extrapolate where I am going with it. I will just add that C++ as a a standard has been adamantly opposed to such ideas, but from this programmer's point of view it will be the way of programming in the future. Without real run-time reflection RAD programming is nearly hopeless. That is the reason why implementing it in D and working toward a RAD programming IDE using D would be a major advantage and selling to using D over and above its additions and possible improvements to C++ IMO. But I do realize how difficult adding run-time reflection may be from the compiler's point of view. Runtime reflection is important, yes, but for a systems programming language like D, compile-time reflection is just as important. FWIW The compiler already outputs some RTTI info, such as the list of modules, the classes in them, and default constructors for classes (if they exist), as well as some typeinfo representing the offsets and types of data members of aggregate types, and "Typeinfo" classes which describe the built-in and user-created/derived types. You can see a limited form of RTTI happening in D's variadic functions -- these functions are passes an array of instances of TypeInfo classes, which correspond to the types of the arguments that were passed. | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply