User Defined Attributes
Walter Bright
newshound2 at digitalmars.com
Tue Nov 6 09:51:23 PST 2012
On 11/6/2012 9:32 AM, David Nadlinger wrote:
> On Tuesday, 6 November 2012 at 17:00:27 UTC, Walter Bright wrote:
>> Ok, I ask again, what use case for a UDA is there for function parameters?
>> (Note that IDL isn't it, as D already has enough parameter attributes to
>> support IDL.)
>
> What »IDL« are you referring to here? At least as far as I am aware, IDL usually
> just refers to an »interface definition language« in general, so I'm not quite
> sure what you mean if you are talking about »enough to support IDL«.
Back in the olden days, Microsoft released a language called IDL (Interface
Definition Language) where you retyped your C function declarations and
annotated them with in, out, and inout. This was used to connect with COM. I
think Microsoft replaced it with extensions to the C compiler.
> Actually, the Thrift IDL would be a perfect example of how attributes on
> parameters can be useful. A simple service definition in a .thrift could look
> like this:
>
> ---
> service Calculator {
> i32 calculate(1:i32 a, 2:i32 b, 3:Op op)
What does this mean? That 'a' is the first parameter and has type i32?
> }
> ---
>
> Note that the parameters are given explicit ids, similar to regular struct
> fields in Thrift, to provide robustness of the generated code against future RPC
> protocol changes (e.g. addition of parameters).
>
> Currently, the equivalent D code for the interface would look something like this:
>
> ---
> interface Calculator : SharedService {
> int calculate(int a, int b, Op op);
>
> enum methodMeta = [
> TMethodMeta(`calculate`,
> [TParamMeta(`a`, 1), TParamMeta(`b`, 2), TParamMeta(`op`, 3)]
> )
> ];
> }
> ---
>
> Being able to assign the IDs in-line using UDAs would make for a much more
> natural method declaration syntax.
More information about the Digitalmars-d-announce
mailing list