Newbie initial comments on D language - delegate

Edward Diener eddielee_no_spam_here at tropicsoft.com
Tue Jan 29 18:24:56 PST 2008


Lionello Lunesu wrote:
> Walter Bright wrote:
>> Edward Diener wrote:
>>> Perhaps there are some implementation issues regarding this which I do
>>> not understand but these should be overcome in order to present a single
>>> interface to the callable concept. Perhaps this has been
>>> discussed ad nauseam on this NG already, so please correct me if I do
>>> not understand all the ramifications of uniting all callable types under
>>> the single idea of 'delegate' while perhaps keeping 'function' around
>>> merely for backward compatibility with old code until eventually it is
>>> dropped.
>>
>> To merge the two requires the generation of thunks at runtime to 
>> manipulate the parameters and calling convention. It's doable, but not 
>> simple.
> 
> Perhaps allowing a delegate to point to a free function is enough to 
> make people happy?
> 
> It sure would please me ;)

Yes, that is the essence of my suggestion.

There is no need to have a separate 'function' as callback since a 
'delegate' should be able to encompass any non-member function also. 
After all if a 'delegate' needs both an object pointer and and a ( 
member ) function pointer, and a 'function' just needs a function 
pointer, then for a delegate encompassing a free function the object 
pointer is just null.

As I originally stated, setting up a callback does NOT care whether what 
is called is a member function or a non-member function, any more than 
an event ( a signal ) cares whether event handlers ( slots  ) are member 
functions or free functions. Furthermore, with both 'function' and 
'delegate' representing callables, setting up a callback, or an event, 
means having to cater to two different types of callables. This just 
complicates what should be a single concept and implementation.

I am sure Walter understands all this and the difficulty in having a 
single callback has nothing to do with the validity of the idea and 
everything to do with the implementation. Yet clearly it is a much 
superior design to the separate 'function'/'delegate' dichotomy.



More information about the Digitalmars-d mailing list