Newbie initial comments on D language - delegate
Don Clugston
dac at nospam.com.au
Wed Jan 30 10:58:08 PST 2008
Janice Caron wrote:
> On Jan 30, 2008 11:17 AM, Don Clugston <dac at nospam.com.au> wrote:
>>>> extern(C) void (*callback)(int,int);
>> That's just 'function', using the hideous C syntax.
>
> Yes, that is precisely my suggestion. I see that as an advantage, not
> a disadvantage, because it would encourage people to use "delegate",
> unless they absolutely couldn't.
>
> All I'm saying is, if you're working in D alone, you can get along
> just fine using "delegate" instead of "function", and therefore the
> keyword "function" is unnecessary.
>
> On the other hand, if you want to interface with C, then you shouldn't
> be surprised if you have to use hideous C syntax.
>
> So we /could/ ditch "function" and have one fewer keyword.
Ah, OK -- that's a reasonable argument. Certainly it does seem that 'function'
is becoming a 'foreign' concept to D; you almost always want to use 'delegate'
instead.
Note (1) 'function' has a different meaning inside is() expressions.
alias void function(int,int) Foo;
static assert (is(Foo == function)); // fails!
Note (2) function pointers do pop up in other places even if you program
exclusively in D, for example in reflection (compile time and runtime). The
vtable is full of function pointers, not delegates.
More information about the Digitalmars-d
mailing list