Is @trusted the wrong direction?

Paolo Invernizzi paolo.invernizzi at gmail.com
Sun Nov 10 11:08:29 UTC 2019


On Saturday, 9 November 2019 at 20:38:47 UTC, Alexandru Ermicioi 
wrote:
> On Saturday, 9 November 2019 at 16:22:05 UTC, Dominikus Dittes 
> Scherkl wrote:
>> I always thought trusted functions shouldn't be a thing. 
>> Almost never a whole function need to be trusted, but only a 
>> few lines of code. What we need instead are trusted blocks. 
>> Those can be simulated with anonymous nested functions, but 
>> the syntax is ugly as hell while complete trusted functions 
>> should be forbidden.
>
> Had an idea how to make more nice trusted blocks:
>
> ```d
> import std.stdio;
>
> T trusted (T)(T delegate() @system dg) @trusted {
>    return dg();
> }
>
> void main() @safe
> {
>     writeln("Hello D");
>
>     ({
>         writeln("C ", cast(void*) 1);
>     }).trusted;
> }
> ```
>
> looks a lot better than anonymous functions that are called 
> right away after being defined.
>
> Best regards,
> Alexandru.

That's exactly the kind of stuff to avoid, in my opinion: for a 
code reviewer point of view, this is just obfuscation, while the 
author should write trusted code in the more pedantic and clear 
way, to facilitate the reviewer analysis.

The whole point, in trusted code, is bond to the fact that the 
code should just be just plain easy to manually be checked.

/Paolo






More information about the Digitalmars-d mailing list