Custom attributes (again)
Walter Bright
newshound2 at digitalmars.com
Fri Apr 6 00:32:40 PDT 2012
On 4/6/2012 12:17 AM, Kapps wrote:
> I like it for the most part. One thing I'd like to see is placing multiple
> attributes both by using multiple @attr()'s, and by using comma separated
> identifier/expression pairs inside a single @attr. In other words, the following
> two declarations would be identical.
>
> @attr(Description = "Blah", ReadOnly)
> int ID;
>
> @attr(Description = "Blah")
> @attr(ReadOnly)
> int ID;
Yes, that makes sense.
> My only concerns:
>
> First, @attr() is a little verbose / not exactly pretty. This isn't really a big
> issue, since attributes aren't exactly piled on and it makes it easy to tell
> what's going on. It is a little uglier than in other languages however.
Could do:
[[name = value]]
I suppose. Not sure what's better.
> Secondly, from what I can tell it's an arbitrary key value combo. What would
> happen if you're working on a larger project and two unrelated libraries try to
> use the same attribute name to mean different things? With the module system
> this issue doesn't exist since you have to import it and can
> selectively/privately do so, but from what I understand the method you're
> proposing doesn't declare the attribute itself at all. Am I just
> misunderstanding this part?
Good question. I don't have experience using attributes, so I don't know if this
would be a problem. Keep in mind that the attribute lookup will only be done for
a particular symbol, there won't be any global lookup.
More information about the Digitalmars-d
mailing list