Jump to page: 1 2 3
Thread overview
Annotations or custom attributes
Mar 09, 2012
Manu
Mar 09, 2012
Jacob Carlborg
Mar 09, 2012
Dmitry Olshansky
Mar 09, 2012
Manu
Mar 09, 2012
bearophile
Mar 09, 2012
Manu
Mar 09, 2012
Jonathan M Davis
Mar 09, 2012
Gor Gyolchanyan
Mar 09, 2012
Jacob Carlborg
Mar 10, 2012
Ary Manzana
Mar 10, 2012
Andrej Mitrovic
Mar 10, 2012
Andrej Mitrovic
Mar 10, 2012
H. S. Teoh
Mar 10, 2012
H. S. Teoh
Mar 10, 2012
Jacob Carlborg
Mar 09, 2012
Manu
Mar 09, 2012
Michel Fortin
Mar 09, 2012
Manu
March 09, 2012
Does D have a nice way to add annotations or custom attributes to entities?

In Java/C# for example, it is common to annotate things with useful compile time information. I'd like to be able to do that in D on occasion.

For instance, I'm serialising some struct/class using reflection to some
text format, but there are a couple of members in a particular class that I
don't want to be written.
A nice solution might be that I could annotate various members:
@DoNotSerialise int thing; ... or something along those lines, whatever
concept you want to apply, which I could then inspect in static if() logic
to produce some requested additional behaviour.

This is a trivial example, but looking at C#/Java, you can see how many
useful things can be done with this sort of system.
How would it be done currently?


March 09, 2012
On 09-03-2012 11:56, Manu wrote:
> Does D have a nice way to add annotations or custom attributes to entities?

Unfortunately, no.

>
> In Java/C# for example, it is common to annotate things with useful
> compile time information. I'd like to be able to do that in D on occasion.

Yes. This is a very needed feature.

>
> For instance, I'm serialising some struct/class using reflection to some
> text format, but there are a couple of members in a particular class
> that I don't want to be written.
> A nice solution might be that I could annotate various members:
> @DoNotSerialise int thing; ... or something along those lines, whatever
> concept you want to apply, which I could then inspect in static if()
> logic to produce some requested additional behaviour.
>
> This is a trivial example, but looking at C#/Java, you can see how many
> useful things can be done with this sort of system.
> How would it be done currently?

Probably not at all (to my knowledge anyway).

-- 
- Alex
March 09, 2012
On 2012-03-09 11:56, Manu wrote:
> Does D have a nice way to add annotations or custom attributes to entities?

Unfortunately no.

> In Java/C# for example, it is common to annotate things with useful
> compile time information. I'd like to be able to do that in D on occasion.
>
> For instance, I'm serialising some struct/class using reflection to some
> text format, but there are a couple of members in a particular class
> that I don't want to be written.
> A nice solution might be that I could annotate various members:
> @DoNotSerialise int thing; ... or something along those lines, whatever
> concept you want to apply, which I could then inspect in static if()
> logic to produce some requested additional behaviour.
>
> This is a trivial example, but looking at C#/Java, you can see how many
> useful things can be done with this sort of system.
> How would it be done currently?

Yeah, it would be so nice to have. As a workaround you can mixin some code, variables or similar in a class/struct.

For serialization you could use my library Orange, which already supports this.

You can have a look at the NonSerialized template at:

http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializable.html

https://github.com/jacob-carlborg/orange

-- 
/Jacob Carlborg
March 09, 2012
On 09.03.2012 14:56, Manu wrote:
> Does D have a nice way to add annotations or custom attributes to entities?
>
There is a potential for them. At least technically everything with @ in front of it was supposed to be an annotation (like @property). I think it's just, sort of, reserved for future.

[...]


-- 
Dmitry Olshansky
March 09, 2012
Okay, so the consensus is, it doesn't currently exist, but there is no real
resistance, and is tentatively planned?
Sounds good to me.

On 9 March 2012 15:42, Dmitry Olshansky <dmitry.olsh@gmail.com> wrote:

> On 09.03.2012 14:56, Manu wrote:
>
>> Does D have a nice way to add annotations or custom attributes to entities?
>>
>>  There is a potential for them. At least technically everything with @ in
> front of it was supposed to be an annotation (like @property). I think it's just, sort of, reserved for future.
>
> [...]
>
>
> --
> Dmitry Olshansky
>


March 09, 2012
Manu:

> Okay, so the consensus is, it doesn't currently exist, but there is no real
> resistance, and is tentatively planned?
> Sounds good to me.

As far as I know there are no concrete ideas yet for the semantics and precise usage of this feature. And I think there are different ideas regarding what this feature has to do (example: I think of it as as a user-defined extension of the type system. Other people think of this feature more like the C#, Scala or Java ones).

So if you want this feature to happen and you have good ideas, then I suggest you to write down a little concrete proposal of definition syntax/semantics (implementation isn't needed now).

Bye,
bearophile
March 09, 2012
On 9 March 2012 17:20, bearophile <bearophileHUGS@lycos.com> wrote:

> Manu:
>
>
>  Okay, so the consensus is, it doesn't currently exist, but there is no
>> real
>> resistance, and is tentatively planned?
>> Sounds good to me.
>>
>
> As far as I know there are no concrete ideas yet for the semantics and precise usage of this feature. And I think there are different ideas regarding what this feature has to do (example: I think of it as as a user-defined extension of the type system. Other people think of this feature more like the C#, Scala or Java ones).
>
> So if you want this feature to happen and you have good ideas, then I suggest you to write down a little concrete proposal of definition syntax/semantics (implementation isn't needed now).
>
> Bye,
> bearophile
>

Okay, well I'll do that at some point, but not now. My other multiple return values thread is about a thousand times more important to me at this point, so I'll keep driving that for the time being :P


March 09, 2012
On 3/9/12 2:56 AM, Manu wrote:
> Does D have a nice way to add annotations or custom attributes to entities?
>
> In Java/C# for example, it is common to annotate things with useful
> compile time information. I'd like to be able to do that in D on occasion.
>
> For instance, I'm serialising some struct/class using reflection to some
> text format, but there are a couple of members in a particular class
> that I don't want to be written.
> A nice solution might be that I could annotate various members:
> @DoNotSerialise int thing; ... or something along those lines, whatever
> concept you want to apply, which I could then inspect in static if()
> logic to produce some requested additional behaviour.
>
> This is a trivial example, but looking at C#/Java, you can see how many
> useful things can be done with this sort of system.
> How would it be done currently?

I think a good approach in D would be to define mixins that work in conjunction with the feature involved, for example:

class A {
    int thing;
    mixin(DoNotSerialize!"thing");
    ...
}

or together:

class A {
    mixin(DoNotSerialize!(int, "thing"));
    ...
}


Andrei
March 09, 2012
That's easy to implement and extremely ugly.

On Fri, Mar 9, 2012 at 8:15 PM, Andrei Alexandrescu <SeeWebsiteForEmail@erdani.org> wrote:
> On 3/9/12 2:56 AM, Manu wrote:
>>
>> Does D have a nice way to add annotations or custom attributes to entities?
>>
>> In Java/C# for example, it is common to annotate things with useful compile time information. I'd like to be able to do that in D on occasion.
>>
>> For instance, I'm serialising some struct/class using reflection to some
>> text format, but there are a couple of members in a particular class
>> that I don't want to be written.
>> A nice solution might be that I could annotate various members:
>> @DoNotSerialise int thing; ... or something along those lines, whatever
>> concept you want to apply, which I could then inspect in static if()
>> logic to produce some requested additional behaviour.
>>
>> This is a trivial example, but looking at C#/Java, you can see how many
>> useful things can be done with this sort of system.
>> How would it be done currently?
>
>
> I think a good approach in D would be to define mixins that work in conjunction with the feature involved, for example:
>
> class A {
>    int thing;
>    mixin(DoNotSerialize!"thing");
>    ...
> }
>
> or together:
>
> class A {
>    mixin(DoNotSerialize!(int, "thing"));
>    ...
> }
>
>
> Andrei



-- 
Bye,
Gor Gyolchanyan.
March 09, 2012
On 2012-03-09 17:15, Andrei Alexandrescu wrote:
> On 3/9/12 2:56 AM, Manu wrote:
>> Does D have a nice way to add annotations or custom attributes to
>> entities?
>>
>> In Java/C# for example, it is common to annotate things with useful
>> compile time information. I'd like to be able to do that in D on
>> occasion.
>>
>> For instance, I'm serialising some struct/class using reflection to some
>> text format, but there are a couple of members in a particular class
>> that I don't want to be written.
>> A nice solution might be that I could annotate various members:
>> @DoNotSerialise int thing; ... or something along those lines, whatever
>> concept you want to apply, which I could then inspect in static if()
>> logic to produce some requested additional behaviour.
>>
>> This is a trivial example, but looking at C#/Java, you can see how many
>> useful things can be done with this sort of system.
>> How would it be done currently?
>
> I think a good approach in D would be to define mixins that work in
> conjunction with the feature involved, for example:
>
> class A {
> int thing;
> mixin(DoNotSerialize!"thing");
> ...
> }
>
> or together:
>
> class A {
> mixin(DoNotSerialize!(int, "thing"));
> ...
> }
>
>
> Andrei

As may serialization library Orange already does: http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializable.html

Look for "NonSerialized".

-- 
/Jacob Carlborg
« First   ‹ Prev
1 2 3