rationale for function and delegate
Jonathan M Davis
jmdavisProg at gmx.com
Sat Oct 16 02:26:09 PDT 2010
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.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list