Thread overview | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
January 20, 2011 Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Not long ago the Java Language people introduced the idea of annotations together with an annotation processing tool (apt). Now perhaps the idea of source code annotations is not actually a Java invention per se, however for someone learning D is there any equivalent idiom [of Java annotations] in the D language? |
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | On 21/01/11 00:47, Justin Johansson wrote:
> Not long ago the Java Language people introduced the idea of annotations
> together with an annotation processing tool (apt).
>
> Now perhaps the idea of source code annotations is not actually a Java
> invention per se, however for someone learning D is there any equivalent
> idiom [of Java annotations] in the D language?
Fair to add that while finding the Java Language annotation concept interesting I am not entirely sure as to its usefulness.
Thanks for answers,
Justin Johansson
|
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj@nospam.com> wrote:
> Not long ago the Java Language people introduced the idea of annotations together with an annotation processing tool (apt).
>
> Now perhaps the idea of source code annotations is not actually a Java invention per se, however for someone learning D is there any equivalent idiom [of Java annotations] in the D language?
Haven't used Java since they added annotations, but I think they are like C# attributes?
In any case, D has an annotation syntax like:
@property
But I think at the moment, annotations have no custom ability. Only compiler-defined annotations are allowed. This may change in the future, but probably not short-term. FWIW, I think we need a much richer runtime-reflection capability before we can use custom annotations to any great effect.
-Steve
|
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 21/01/11 01:02, Steven Schveighoffer wrote:
> On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj@nospam.com> wrote:
>
>> Not long ago the Java Language people introduced the idea of
>> annotations together with an annotation processing tool (apt).
>>
>> Now perhaps the idea of source code annotations is not actually a Java
>> invention per se, however for someone learning D is there any
>> equivalent idiom [of Java annotations] in the D language?
>
> Haven't used Java since they added annotations, but I think they are
> like C# attributes?
>
> In any case, D has an annotation syntax like:
>
> @property
>
> But I think at the moment, annotations have no custom ability. Only
> compiler-defined annotations are allowed. This may change in the future,
> but probably not short-term. FWIW, I think we need a much richer
> runtime-reflection capability before we can use custom annotations to
> any great effect.
>
> -Steve
Thanks for answer. I wasn't expecting many enlightening responses. Yours was a pleasant reply, albeit a reflection of the current state of D.
- Justin
|
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | Justin Johansson Wrote: > Thanks for answer. I wasn't expecting many enlightening responses. Yours was a pleasant reply, albeit a reflection of the current state of D. > > - Justin I think it is worth mentioning that the current syntax comes from DIP 6 http://www.prowiki.org/wiki4d/wiki.cgi?LanguageDevel/DIPs/DIP6 As whether custom annotations will happen, I haven't heard an official word. But it was somewhat an implied intent. |
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer | On 2011-01-20 15:02, Steven Schveighoffer wrote: > On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj@nospam.com> wrote: > >> Not long ago the Java Language people introduced the idea of >> annotations together with an annotation processing tool (apt). >> >> Now perhaps the idea of source code annotations is not actually a Java >> invention per se, however for someone learning D is there any >> equivalent idiom [of Java annotations] in the D language? > > Haven't used Java since they added annotations, but I think they are > like C# attributes? > > In any case, D has an annotation syntax like: > > @property > > But I think at the moment, annotations have no custom ability. Only > compiler-defined annotations are allowed. This may change in the future, > but probably not short-term. FWIW, I think we need a much richer > runtime-reflection capability before we can use custom annotations to > any great effect. > > -Steve I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations. -- /Jacob Carlborg |
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Steven Schveighoffer Attachments:
| On Thu, Jan 20, 2011 at 8:02 AM, Steven Schveighoffer <schveiguy@yahoo.com>wrote:
> On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj@nospam.com> wrote:
>
> Not long ago the Java Language people introduced the idea of annotations
>> together with an annotation processing tool (apt).
>>
>> Now perhaps the idea of source code annotations is not actually a Java invention per se, however for someone learning D is there any equivalent idiom [of Java annotations] in the D language?
>>
>
> Haven't used Java since they added annotations, but I think they are like C# attributes?
>
> In any case, D has an annotation syntax like:
>
> @property
>
> But I think at the moment, annotations have no custom ability. Only compiler-defined annotations are allowed. This may change in the future, but probably not short-term. FWIW, I think we need a much richer runtime-reflection capability before we can use custom annotations to any great effect.
>
I would find it useful to be able to access annotations as part of compile time reflection, actually, but AFAIK no progress has been made on that front so far.
|
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Justin Johansson | On 2011-01-20 14:47, Justin Johansson wrote: > Not long ago the Java Language people introduced the idea of annotations > together with an annotation processing tool (apt). > > Now perhaps the idea of source code annotations is not actually a Java > invention per se, however for someone learning D is there any equivalent > idiom [of Java annotations] in the D language? Depending on what you want to do you can create a template mixin that accepts string(s)/alias(es). For example: for the serialization library (http://dsource.org/projects/orange) I'm working on the following syntax is used: class Foo { int x; int y; int z; mixin NonSerialized!(z); } The above mixin indicates that the "z" instance variable shouldn't be serialized. This is (currently) achieved by defining a field in the mixed in template (which will be added to the class) which is a struct containing the string of the filed which shouldn't be serialized. Then I iterate over all the fields in the class with .tupleof and collects all mixed in fields in a list. Then I know what fields to skip later during the serialization. -- /Jacob Carlborg |
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob@me.com> wrote:
> On 2011-01-20 15:02, Steven Schveighoffer wrote:
>> On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj@nospam.com> wrote:
>>
>>> Not long ago the Java Language people introduced the idea of
>>> annotations together with an annotation processing tool (apt).
>>>
>>> Now perhaps the idea of source code annotations is not actually a Java
>>> invention per se, however for someone learning D is there any
>>> equivalent idiom [of Java annotations] in the D language?
>>
>> Haven't used Java since they added annotations, but I think they are
>> like C# attributes?
>>
>> In any case, D has an annotation syntax like:
>>
>> @property
>>
>> But I think at the moment, annotations have no custom ability. Only
>> compiler-defined annotations are allowed. This may change in the future,
>> but probably not short-term. FWIW, I think we need a much richer
>> runtime-reflection capability before we can use custom annotations to
>> any great effect.
>>
>> -Steve
>
> I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.
I don't think it's the same thing. Keywords are not allowed to be used anywhere else, even for things that would parse properly were they not keywords. They are anchors for the parser to determine where it is. In contrast, a compiler-defined annotation is parsed just the same as a custom one, it's just that the meaning is predefined.
For example, you can legally do:
int property;
without error, but this won't even get past the parsing stage:
int struct;
-Steve
|
January 20, 2011 Re: Source code annotations alla Java | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | > class Foo > { > int x; > int y; > int z; > > mixin NonSerialized!(z); > } Had a quick look at http://dsource.org/projects/orange/browser/orange/serialization/Serializable.d 1. How come it works without 'mixin' in the template declaration (mixin template NonSerialized)? 2. What if several fields need to be tagged? 3. Is there a reason to use a struct instead of e.g. __nonSerialized = ["field1", "field2", ...]? 4. Couldn't that field be static to save space or maybe even enum? |
Copyright © 1999-2021 by the D Language Foundation