User Defined Attributes

Leandro Lucarella luca at llucax.com.ar
Wed Nov 14 06:31:22 PST 2012


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?

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;
}

-- 


More information about the Digitalmars-d-announce mailing list