rationale for function and delegate

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Oct 16 06:57:41 PDT 2010


On 10/16/10 4:26 CDT, Jonathan M Davis wrote:
> On Saturday 16 October 2010 01:40:55 Paulo Pinto wrote:
>> Hi,
>>
>> while reading TDPL I start wondering what is the background between
>> function and delegate.
>>
>> They seem to provide more or less the same funcionality, except delegate
>> allows the capture
>> of the function declaration environment.
>>
>> Most of the programming languages with support for closures only have one
>> way of doing it.
>>
>> Why is D providing two ways of doing it? For me sounds like a feature
>> similar to register, or
>> inline for doing what should be the compilers work. Deciding the best
>> implementation for the
>> closure.
>>
>> Thanks,
>> Paulo
>
> I believe that the two main reasons are
>
> 1. function pointers have less overhead.
>
> 2. If you want to use function pointers when calling C functions, you need
> function pointers rather than delegates.
>
> but there are probably others.

That's about it. The book mentions 2, whereas 1 is implied.

Andrei



More information about the Digitalmars-d mailing list