named arguments, string interpolation, please stop.

Timon Gehr timon.gehr at gmx.ch
Thu Jan 11 22:33:58 UTC 2024


On 1/11/24 23:24, Richard (Rikki) Andrew Cattermole wrote:
> 
> On 12/01/2024 11:17 AM, Timon Gehr wrote:
>> On 1/11/24 22:37, Walter Bright wrote:
>>
>>     On 1/11/2024 1:18 PM, DrDread wrote:
>>
>>         this is discarding the use case that you want to mark only parts
>>         of your codebase nogc, but enforce it'S really nogc. we do use
>>         some realtime threads, but the rest off the app is @gc.
>>
>>     This subthread suggests to me that the problem with @nogc is it
>>     works. ...
>>
>> It does not work. There are two options:
>>
>>   * Mark the function and callback |@nogc|, then GC users cannot use
>>     your library.
>>   * Mark the function and callback not |@nogc|, then |@nogc| users
>>     cannot use your library.
> 
> Indeed, what I want is contract invalidation.
> 
> ```d
> void func(void delegate() @safe @nogc del) @safe @nogc {
>      del();
> }
> ```
> 
> If we pass in ``@nogc`` delegate, it works as is.
> 
> If we don't the caller sees:
> 
> ```d
> void func(void delegate() @system del) @system {
>      del();
> }
> ```
> 
> It's ``@system`` simply because the delegate is not ``scope`` and 
> therefore can escape, otherwise with DIP1000 and ``scope`` would still 
> be ``@safe``.
> 
> This would not replace attribute inference. But instead help interfacing 
> code that needs those guarantees versus those that don't.

If you do that D can no longer correctly implement a higher-order 
function that forms the composed function from its two arguments. It 
looks good on paper for a few minutes, but this is not a good solution 
to apply by default.


More information about the Digitalmars-d mailing list