digitalmars.D.learn - Source code annotations alla Java
- Justin Johansson (5/5) Jan 20 2011 Not long ago the Java Language people introduced the idea of annotations...
- Justin Johansson (5/10) Jan 20 2011 Fair to add that while finding the Java Language annotation concept
- Steven Schveighoffer (11/16) Jan 20 2011 Haven't used Java since they added annotations, but I think they are lik...
- Justin Johansson (4/21) Jan 20 2011 Thanks for answer. I wasn't expecting many enlightening responses.
- Jesse Phillips (4/8) Jan 20 2011 I think it is worth mentioning that the current syntax comes from DIP 6
- Jacob Carlborg (5/22) Jan 20 2011 I would rather formulate it like: currently D has a syntax for keywords
- Steven Schveighoffer (11/38) Jan 20 2011 I don't think it's the same thing. Keywords are not allowed to be used ...
- Jacob Carlborg (4/43) Jan 20 2011 I assume you meant "int @property;"?
- Steven Schveighoffer (14/64) Jan 20 2011 No. I meant int property;
- Jacob Carlborg (8/73) Jan 20 2011 Of course that would work, isn't that like saying this won't work:
- Ary Manzana (13/89) Jan 21 2011 Jacob is right here.
- Jonathan M Davis (12/112) Jan 21 2011 No. No attributes are keywords. The reasoning is simple. A keyword is a ...
- Jay Norwood (8/160) Jan 29 2014 I see eclipse4 used java annotations heavily to mark up code
- Andrew Wiley (5/23) Jan 20 2011 I would find it useful to be able to access annotations as part of compi...
- Paulo Pinto (5/16) Dec 10 2014 Yes, this is one case where Java copied back from C#.
- Jacob Carlborg (21/26) Jan 20 2011 Depending on what you want to do you can create a template mixin that
- Trass3r (8/15) Jan 20 2011 Had a quick look at
- Simen kjaeraas (7/19) Jan 20 2011 Templates are not currently required to be marked as mixin templates in ...
- Jacob Carlborg (16/32) Jan 20 2011 You use the mixin several times.
- Trass3r (7/9) Jan 20 2011 Well at least the following compiles:
- Mengu (6/35) Jan 30 2014 let's assume you are building a web application and you want to
- Denis Gladkiy (3/9) Dec 09 2014 They are here: http://dlang.org/attribute.html#uda
- Steven Schveighoffer (3/11) Dec 11 2014 This is an almost-4-year-old thread.
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?
Jan 20 2011
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
Jan 20 2011
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 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
Jan 20 2011
On 21/01/11 01:02, Steven Schveighoffer wrote:On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> 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. - JustinNot 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 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
Jan 20 2011
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. - JustinI 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.
Jan 20 2011
On 2011-01-20 15:02, Steven Schveighoffer wrote:On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations. -- /Jacob CarlborgNot 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 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
Jan 20 2011
On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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
Jan 20 2011
On 2011-01-20 19:18, Steven Schveighoffer wrote:On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"? -- /Jacob CarlborgOn 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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
Jan 20 2011
On Thu, 20 Jan 2011 15:03:55 -0500, Jacob Carlborg <doob me.com> wrote:On 2011-01-20 19:18, Steven Schveighoffer wrote:No. I meant int property; A keyword is specifically not allowed where the grammar would otherwise allow it. A symbol isn't allowed to have in it, so this naturally prevents a conflict. I realize the poor example, but it's definitely not a keyword. Otherwise, it would be listed here: http://www.digitalmars.com/d/2.0/lex.html#keyword (actually, are annotations part of the lexical grammar there?). It's more like Object, which is not a keyword, but you aren't allowed to use it to mean anything besides what it means. The end result is, it fails if you use it in the wrong place, but the keyword status makes it fail at the parsing stage. I am not a compiler writer, so I'm talking a bit from my ass here. -SteveOn Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"?On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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
Jan 20 2011
On 2011-01-20 21:34, Steven Schveighoffer wrote:On Thu, 20 Jan 2011 15:03:55 -0500, Jacob Carlborg <doob me.com> wrote:Of course that would work, isn't that like saying this won't work: int struct_; // ?On 2011-01-20 19:18, Steven Schveighoffer wrote:No. I meant int property;On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"?On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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. -SteveA keyword is specifically not allowed where the grammar would otherwise allow it. A symbol isn't allowed to have in it, so this naturally prevents a conflict. I realize the poor example, but it's definitely not a keyword. Otherwise, it would be listed here: http://www.digitalmars.com/d/2.0/lex.html#keyword (actually, are annotations part of the lexical grammar there?). It's more like Object, which is not a keyword, but you aren't allowed to use it to mean anything besides what it means. The end result is, it fails if you use it in the wrong place, but the keyword status makes it fail at the parsing stage. I am not a compiler writer, so I'm talking a bit from my ass here. -SteveOk, maybe you're right. I'm pretty sure, as you say, that a keyword in the wrong place would fail during parsing. But I don't know where a misplaced annotation/attribute would fail. -- /Jacob Carlborg
Jan 20 2011
On 1/20/11 5:48 PM, Jacob Carlborg wrote:On 2011-01-20 21:34, Steven Schveighoffer wrote:Jacob is right here. This, as you say, fails: int struct; And also this fails: int property; So yes, currently property is just a keyword with a prepended . D. For example, as it is said in DIP6, you could have: extern('C') void someFunc(); instead of having extern a keyword and thus being unable to use it for identifiers.On Thu, 20 Jan 2011 15:03:55 -0500, Jacob Carlborg <doob me.com> wrote:Of course that would work, isn't that like saying this won't work: int struct_; // ?On 2011-01-20 19:18, Steven Schveighoffer wrote:No. I meant int property;On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"?On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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. -SteveA keyword is specifically not allowed where the grammar would otherwise allow it. A symbol isn't allowed to have in it, so this naturally prevents a conflict. I realize the poor example, but it's definitely not a keyword. Otherwise, it would be listed here: http://www.digitalmars.com/d/2.0/lex.html#keyword (actually, are annotations part of the lexical grammar there?). It's more like Object, which is not a keyword, but you aren't allowed to use it to mean anything besides what it means. The end result is, it fails if you use it in the wrong place, but the keyword status makes it fail at the parsing stage. I am not a compiler writer, so I'm talking a bit from my ass here. -SteveOk, maybe you're right. I'm pretty sure, as you say, that a keyword in the wrong place would fail during parsing. But I don't know where a misplaced annotation/attribute would fail.
Jan 21 2011
On Friday, January 21, 2011 12:36:23 Ary Manzana wrote:On 1/20/11 5:48 PM, Jacob Carlborg wrote:No. No attributes are keywords. The reasoning is simple. A keyword is a word that would be a valid identifier but isn't, because the language treats it as special. is not a valid part of an identifier. So, property can't be a keyword. And property certainly isn't a keyword, since you _can_ use it as an identifier, so it isn't a keyword with prepended on either. True, property is treated as a special symbol by the compiler, and I don't expect that it really treats it like an attribute with the name property (which it will pretty much have to do if we ever get user-defined attributes), but definitely isn't a keyword, because it was never possible for it to be a valid identifier in the first place. - Jonathan M DavisOn 2011-01-20 21:34, Steven Schveighoffer wrote:Jacob is right here. This, as you say, fails: int struct; And also this fails: int property; So yes, currently property is just a keyword with a prepended . D. For example, as it is said in DIP6, you could have: extern('C') void someFunc(); instead of having extern a keyword and thus being unable to use it for identifiers.On Thu, 20 Jan 2011 15:03:55 -0500, Jacob Carlborg <doob me.com> wrote:Of course that would work, isn't that like saying this won't work: int struct_; // ?On 2011-01-20 19:18, Steven Schveighoffer wrote:No. I meant int property;On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"?On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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. -SteveA keyword is specifically not allowed where the grammar would otherwise allow it. A symbol isn't allowed to have in it, so this naturally prevents a conflict. I realize the poor example, but it's definitely not a keyword. Otherwise, it would be listed here: http://www.digitalmars.com/d/2.0/lex.html#keyword (actually, are annotations part of the lexical grammar there?). It's more like Object, which is not a keyword, but you aren't allowed to use it to mean anything besides what it means. The end result is, it fails if you use it in the wrong place, but the keyword status makes it fail at the parsing stage. I am not a compiler writer, so I'm talking a bit from my ass here. -SteveOk, maybe you're right. I'm pretty sure, as you say, that a keyword in the wrong place would fail during parsing. But I don't know where a misplaced annotation/attribute would fail.
Jan 21 2011
On Friday, 21 January 2011 at 20:50:39 UTC, Jonathan M Davis wrote:On Friday, January 21, 2011 12:36:23 Ary Manzana wrote:I see eclipse4 used java annotations heavily to mark up code for dependency injection in the new ide framework. Someone recommended use of mixin in this thread, in place of the java use of user defined annotations. Is that still the recommended D solution for handling ports of java annotations? https://wiki.eclipse.org/Eclipse4/RCP/Dependency_InjectionOn 1/20/11 5:48 PM, Jacob Carlborg wrote:No. No attributes are keywords. The reasoning is simple. A keyword is a word that would be a valid identifier but isn't, because the language treats it as special. is not a valid part of an identifier. So, property can't be a keyword. And property certainly isn't a keyword, since you _can_ use it as an identifier, so it isn't a keyword with prepended on either. True, property is treated as a special symbol by the compiler, and I don't expect that it really treats it like an attribute with the name property (which it will pretty much have to do if we ever get user-defined attributes), but definitely isn't a keyword, because it was never possible for it to be a valid identifier in the first place. - Jonathan M DavisOn 2011-01-20 21:34, Steven Schveighoffer wrote:Jacob is right here. This, as you say, fails: int struct; And also this fails: int property; So yes, currently property is just a keyword with a prepended . case in D. For example, as it is said in DIP6, you could have: extern('C') void someFunc(); instead of having extern a keyword and thus being unable to use it for identifiers.On Thu, 20 Jan 2011 15:03:55 -0500, Jacob Carlborg <doob me.com> wrote:Of course that would work, isn't that like saying this won't work: int struct_; // ?On 2011-01-20 19:18, Steven Schveighoffer wrote:No. I meant int property;On Thu, 20 Jan 2011 13:07:58 -0500, Jacob Carlborg <doob me.com> wrote:I assume you meant "int property;"?On 2011-01-20 15:02, Steven Schveighoffer wrote: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; -SteveOn Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:I would rather formulate it like: currently D has a syntax for keywords that are similar to Java annotations.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 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. -SteveA keyword is specifically not allowed where the grammar would otherwise allow it. A symbol isn't allowed to have in it, so this naturally prevents a conflict. I realize the poor example, but it's definitely not a keyword. Otherwise, it would be listed here: http://www.digitalmars.com/d/2.0/lex.html#keyword (actually, are annotations part of the lexical grammar there?). It's more like Object, which is not a keyword, but you aren't allowed to use it to mean anything besides what it means. The end result is, it fails if you use it in the wrong place, but the keyword status makes it fail at the parsing stage. I am not a compiler writer, so I'm talking a bit from my ass here. -SteveOk, maybe you're right. I'm pretty sure, as you say, that a keyword in the wrong place would fail during parsing. But I don't know where a misplaced annotation/attribute would fail.
Jan 29 2014
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 annotationsI 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.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 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.
Jan 20 2011
On Thursday, 20 January 2011 at 14:04:54 UTC, Steven Schveighoffer wrote:On Thu, 20 Jan 2011 08:47:28 -0500, Justin Johansson <jj nospam.com> wrote:-- PauloNot 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
Dec 10 2014
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
Jan 20 2011
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?
Jan 20 2011
Trass3r <un known.com> wrote:Templates are not currently required to be marked as mixin templates in order to be used as such. However, a mixin template can only be instantiated as a mixin. -- Simenclass 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)?
Jan 20 2011
On 2011-01-20 20:10, Trass3r wrote:I think it's optional, it works with DMD 2.052class 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?You use the mixin several times.3. Is there a reason to use a struct instead of e.g. __nonSerialized = ["field1", "field2", ...]?Hmm, I think I had a good reason. First it needs to be const so it works during compile time. But I think I used a struct because I used that on another project which required more data than just then name the field. If I would store it in an array you could only do the mixin once, I think. And that would require you to use strings instead of aliases, I think. template foo (args...) {} Does that work with aliases?4. Couldn't that field be static to save space or maybe even enum?That field should absolutely be static, I'm currently working on fixing that. I didn't think of that when I implemented it. This will also only work with one mixin (see the answer for the third comment). -- /Jacob Carlborg
Jan 20 2011
template foo (args...) {} Does that work with aliases?Well at least the following compiles: template Foo(T...,) { int i; } int a,b; alias Foo!(a,b) f;
Jan 20 2011
On Thursday, 20 January 2011 at 18:19:21 UTC, Jacob Carlborg wrote:On 2011-01-20 14:47, Justin Johansson wrote:let's assume you are building a web application and you want to keep that controller only for the logged in users. in java you can create an annotation class called RequireLogin and put your logic there. mixins are not the way for this.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.
Jan 30 2014
On Thursday, 20 January 2011 at 13:49:30 UTC, 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?They are here: http://dlang.org/attribute.html#uda
Dec 09 2014
On 12/10/14 1:16 AM, Denis Gladkiy wrote:On Thursday, 20 January 2011 at 13:49:30 UTC, Justin Johansson wrote:This is an almost-4-year-old thread. -SteveNot 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?They are here: http://dlang.org/attribute.html#uda
Dec 11 2014