User Defined Attributes
deadalnix
deadalnix at gmail.com
Fri Nov 16 10:51:41 PST 2012
Le 14/11/2012 22:13, Walter Bright a écrit :
> On 11/14/2012 2:53 AM, Jacob Carlborg wrote:
>> If "std.mytypes.mystring" is a variable of the type "string" then the
>> fully
>> qualified name is lost if it's used as an attribute. Something like this:
>
> I am having a REALLY hard time making my point here.
>
> struct MyString
> {
> string s;
> }
>
> Now use MyString as an attribute. No, the name is not lost. Yes, two
> different modules can use MyString as an attribute, and impute
> completely different meanings into it.
>
> Just because it is not a builtin type does not change anything.
I seriously feel like I'm in Alice in wonderland here.
A type is a meaning associated to data. For instance, char[] is an array
of char. Note that you can store pointers, integer, or basically
anything in that memory. But you don't, because this type give you
information about what in this memory, and storing anything else would
be confusing as hell.
The same way, I can throw a FileExeption every time a problem occurs in
any of my programs. That would be insane, but i CAN do that.
Well, the same way, I can subvert attribute in any convoluted way I want
to. But that make no sens at all (and I don't expect any codebase using
such techniques to become really big).
The whole point of attaching data to a symbol via attribute is to
provide a meaning attached to that symbol. The meaning is given by the
type, like it does everywhere else.
Your MyString example or an int is a perfect example of a type that have
no meaning. Your argument is just like we shouldn't put any protection
near a precipice since people can throw themselves over it anyway. Yeah,
but at least, they'll do it on purpose and assume the consequences, and
that is a huge win.
More information about the Digitalmars-d-announce
mailing list