Discussion Thread: DIP 1033--Implicit Conversion of Expressions to Delegates--Community Review Round 1

aliak something at something.com
Thu Apr 23 09:33:35 UTC 2020


On Wednesday, 22 April 2020 at 11:56:44 UTC, kinke wrote:
> I don't think this is a good idea. One of the problems with 
> `lazy` IMO is that one needs good IDE support to somehow 
> highlight that the argument expression isn't evaluated before 
> the call, and might not be evaluated at all:
>
> // in some other module:
> void foo(lazy int i) {}
>
> void main()
> {
>     int i = 1;
>     foo(++i);
>     assert(i == 1); // what? not incremented above? ah yeah, 
> lazy and not evaluated at all by foo
> }
>
> The proposal would extend that problem to regular delegate 
> params too. So I find the explicit version (`() => ++i`) better 
> to make that clear. I don't think the 'overhead' of putting an 
> additional `() =>` in front of the expression justifies 
> introducing the proposed implicit convertibility.

I agree with this. Implicit conversion has always been argued 
against in D - why is it ok now? And this is not the good kind of 
implicit conversion where the user explicitly asks for it, but 
the bad kind where the language decides it should happen and the 
user doesn't know it can even happen.

Thinking about it more now feels like the real rationale for the 
DIP is "in order to deprecate lazy, we need an alternative" ... 
???



More information about the Digitalmars-d mailing list