User Defined Attributes

Timon Gehr timon.gehr at gmx.ch
Wed Nov 14 08:25:07 PST 2012


On 11/14/2012 03:31 PM, Leandro Lucarella wrote:
> Tove, el 14 de November a las 13:55 me escribiste:
>>> struct UserProfile {
>>>     @Id(1) i32 uid;
>>>     @Id(2) string name;
>>>     @Id(3) string blurb;
>>> }
>>>
>>> Where Id is "thrift.attributes.Id" or something similar.
>>
>> well, similar... but beginning with a symbol...
>>
>> [thrift.attributes.Definition]
>> struct UserProfile
>> {
>>    [1] i32 uid;
>>    [2] string name;
>>    [3] string blurb;
>> }
>
> OK, that's just a good example of convenience of allowing native types, but I
> think it is still potentially harmful. What if you pass that struct to another
> library that have another meaning attached to int annotations? How could you
> tell that library that this particular int annotations is not for it?
> ...

By not telling it that they are for it. Note that the 
[thrift.attributes.Definition] annotation is significant.

> I mean, it convenient to be able to throw numbers or strings too:
>
> void f() { throw 1; }
>
> void g() { throw "error"; }
>
> int main()
> {
> 	try {
> 		g();
> 	} catch (char[] e) {
> 		writefln(e);
> 	}
> 	try {
> 		f();
> 	} catch (int i) {
> 		return i;
> 	}
> 	return 0;
> }
>

What he does is more like (but not exactly like):

class ThriftException{
     int x;
     this(int x){ this.x = x; }
}





More information about the Digitalmars-d-announce mailing list