Discussion Thread: DIP 1032--Function pointers and Delegate Parameters...--Community Review Round 1

H. S. Teoh hsteoh at quickfur.ath.cx
Sat Apr 4 00:09:49 UTC 2020


> On Friday, 3 April 2020 at 10:30:33 UTC, Mike Parker wrote:
> > This is the discussion thread for the first round of Community
> > Review of DIP 1032, "Function pointers and Delegate Parameters
> > Inherit Attributes from Function":
> > 
> > https://github.com/dlang/DIPs/blob/0c99bd854302ade3e6833080410e9050fddec346/DIPs/DIP1032.md
> > 
> > The review period will end at 11:59 PM ET on April 17, or when I
> > make a post declaring it complete. Discussion in this thread may
> > continue beyond that point.
> > 
> > Here in the discussion thread, you are free to discuss anything and
> > everything related to the DIP. Express your support or opposition,
> > debate alternatives, argue the merits, etc.
[...]

I echo Dukc's concerns from the other thread, that this DIP seems to be
approaching the problem in the wrong way.

What I often find myself needing is not that delegates inherit
attributes from the function it's passed to, but rather the reverse:
that the *function* inherits the attributes of the passed-in delegate.

The whole point of a delegate is to insert arbitrary code into a
function at certain points, so usually one wants maximum freedom for the
caller to pass in a delegate with any set of attributes.  Why limit what
the caller can do?  If the caller wants to pass in a @system delegate,
then so be it, let him do whatever he wants.  From the POV of a library
author, I want my code to be maximally reusable, so as much as possible
I don't want to limit what my callers can pass to me.

What *I*, the function implementor, am concerned with is that *my* code,
that is, the function body besides the calls to the delegate, conforms
to certain attributes, such as @safe.  By doing so, I make it possible
for @safe callers to use my function -- if they pass in a @safe
delegate, then my function should be @safe.  If the delegate they pass
in is @system, then obviously my function should also be @system.

I've almost never found a need for my function to impose restrictions on
a passed-in delegate -- the delegate is the caller's problem, I don't
care what they do with it.  I want my function to accomodate both @safe
and @system delegates, and I want my function to be usable with both
@safe and @system callers (the former case conditional upon the delegate
being @safe).  Why would I want to limit what kind of delegates the
caller passes to me?  If the delegate does something bad, that's the
caller's problem, not mine.  My concern is only that my code accomodates
callers with any attribute sets, whether they can actually call me with
that attribute set is up to them -- by ensuring the delegate they give
me conforms to said attributes.  It's not my function's responsibility
to enforce what the caller does with the delegate; it's the caller's
responsibility to give me a delegate with the attributes that the caller
wants from my function.

IOW, it should be the *function* that inherits attributes from the
passed-in delegate, not the other way round as proposed by this DIP.


T

-- 
When solving a problem, take care that you do not become part of the problem.


More information about the Digitalmars-d mailing list