View mode: basic / threaded / horizontal-split · Log in · Help
March 09, 2012
Re: Annotations or custom attributes
On 9 March 2012 18:15, 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
>

Yep, that sure is horribly ugly! Sadly, that's what I thought the case was
currently. Let's hope for user defined attributes in the future ;)
March 09, 2012
Re: Annotations or custom attributes
On 2012-03-09 16:15:30 +0000, Andrei Alexandrescu 
<SeeWebsiteForEmail@erdani.org> said:

> 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"));
>      ...
> }

It's ugly, but it works… only to a point though. Try to annotate 
overloaded functions and it'll become a mess: either you duplicate the 
function name and all the argument types for each function, or you wrap 
the whole function body in the mixin.

If you need to annotate a struct or a class you'll have the same 
problem, just at a bigger scale. And it gets worse if you want to 
annotate templated types and functions: how can the attribute apply to 
each instance?

I'm not saying any of this is impossible using mixins, just that it 
becomes impractical as you go beyond the most simple cases.

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/
March 09, 2012
Re: Annotations or custom attributes
On 9 March 2012 19:23, Michel Fortin <michel.fortin@michelf.com> wrote:

> On 2012-03-09 16:15:30 +0000, Andrei Alexandrescu <
> SeeWebsiteForEmail@erdani.org**> said:
>
>  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"));
>>     ...
>> }
>>
>
> It's ugly, but it works… only to a point though. Try to annotate
> overloaded functions and it'll become a mess: either you duplicate the
> function name and all the argument types for each function, or you wrap the
> whole function body in the mixin.
>
> If you need to annotate a struct or a class you'll have the same problem,
> just at a bigger scale. And it gets worse if you want to annotate templated
> types and functions: how can the attribute apply to each instance?
>
> I'm not saying any of this is impossible using mixins, just that it
> becomes impractical as you go beyond the most simple cases.


It seems to me that everyone agrees on the usefulness of proper user
defined annotations, so I'm personally satisfied that it *will* come :) ..
It's certainly not urgent for me, but it sure would be nice!
March 09, 2012
Re: Annotations or custom attributes
On Friday, March 09, 2012 16:00:03 Manu wrote:
> Okay, so the consensus is, it doesn't currently exist, but there is no real
> resistance, and is tentatively planned?
> Sounds good to me.

I wouldn't really say that it's tentatively planned. I don't recall Walter 
ever weighing in on it at all, and no one is working on it. Rather, the 
current situation does not prevent it, and there's definitely some desire for 
it in the community, so there's a decent chance that it'll be implemented 
eventually. There are no plans for it though.

Regardless, adding them should be backwards compatible, so it's really not a 
problem to wait until other more pressing issues have been addressed and the 
language has better stabilized before adding such a feature.

- Jonathan M Davis
March 09, 2012
Re: Annotations or custom attributes
On 3/9/12 8:30 AM, Jacob Carlborg wrote:
> As may serialization library Orange already does:
> http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializable.html
>
>
> Look for "NonSerialized".

Saw that after posting. Cool!

Andrei

P.S. Please don't overquote, you systematically do so. Thanks!
March 09, 2012
Re: Annotations or custom attributes
On Fri, 09 Mar 2012 18:23:17 -0500, Andrei Alexandrescu  
<SeeWebsiteForEmail@erdani.org> wrote:

> On 3/9/12 8:30 AM, Jacob Carlborg wrote:
>> As may serialization library Orange already does:
>> http://dl.dropbox.com/u/18386187/orange_docs/orange.serialization.Serializable.html
>>
>>
>> Look for "NonSerialized".
>
> Saw that after posting. Cool!
>
> Andrei
>
> P.S. Please don't overquote, you systematically do so. Thanks!

Please continue to quote the previous two messages for context if you feel  
like it.  I enjoy not having to look back to previous messages.  Thanks!

-Steve
March 10, 2012
Re: Annotations or custom attributes
What are you talking about?
March 10, 2012
Re: Annotations or custom attributes
On Fri, 09 Mar 2012 19:05:00 -0500, Ary Manzana <ary@esperanto.org.ar>  
wrote:

> What are you talking about?

Who are you talking to?

:)

Seriously, though, I think Andrej sometimes quotes *nothing* (no offense  
for picking on you Andrej), and couple that with the newsgroup's seemingly  
random decision to start a new thread, or put a reply at the same level, I  
sometimes have no idea what he's talking about :)

-Steve
March 10, 2012
Re: Annotations or custom attributes
On 3/10/12, Steven Schveighoffer <schveiguy@yahoo.com> wrote:
> Seriously, though, I think Andrej sometimes quotes *nothing* (no offense
> for picking on you Andrej), and couple that with the newsgroup's seemingly
> random decision to start a new thread, or put a reply at the same level, I
> sometimes have no idea what he's talking about :)

LOL. I was honestly wondering if this was an issue or not. I blame the
gmail quick-reply box. It has two options: quote everything, or quote
nothing. Otherwise there's a full reply button and then I can quickly
select a piece of text to quote. But I *thought* that by using quick
reply without fully quoting it would mean my reply would sit right
next to the last poster's reply.

I'm just used to using forum software and when I do a quick-reply
there my post is right below the last user's post, and it's easy to
figure out who I'm replying to.

Anyway, I'll stop posting replies to the void. :p (thanks for letting
me know btw)
March 10, 2012
Re: Annotations or custom attributes
On Fri, Mar 09, 2012 at 07:24:34PM -0500, Steven Schveighoffer wrote:
> On Fri, 09 Mar 2012 19:05:00 -0500, Ary Manzana
> <ary@esperanto.org.ar> wrote:
> 
> >What are you talking about?
> 
> Who are you talking to?
> 
> :)
> 
> Seriously, though, I think Andrej sometimes quotes *nothing* (no
> offense for picking on you Andrej), and couple that with the
> newsgroup's seemingly random decision to start a new thread, or put
> a reply at the same level, I sometimes have no idea what he's
> talking about :)
[...]

You guys should just use a threading mail reader. Like mutt. :-P :-P
(Though Ary's post didn't make sense to me either, because I'd deleted
the parent post already. Ah well. The joys of impersonal online
communication...)


T

-- 
I see that you JS got Bach.
1 2 3
Top | Discussion index | About this forum | D home