@system blocks and safer @trusted (ST) functions

ag0aep6g anonymous at example.com
Mon Jul 26 00:21:32 UTC 2021


On Sunday, 25 July 2021 at 23:16:16 UTC, jfondren wrote:
> I recommend this justification for the DIP: what you are doing 
> is *rehabilitating @trusted functions*, which are currently 
> (for newbies) a bug-filled trap, and (for experts) disused in 
> favor of @safe functions containing @trusted blocks. The 
> language documentation tells people to use @trusted functions 
> but the language in practice doesn't really have them.

The language doesn't have @trusted blocks. @trusted function 
literals (lambdas) are still functions. Everything the 
documentation says about @trusted functions applies to function 
literals.

People do like to treat @trusted function literals as if they 
were the proposed @system blocks. But then they're strictly 
speaking writing invalid code. They're cheating. And why not? It 
has significant advantages for the low price of (1) tainting some 
@safe code and (2) having a technically invalid program that 
works just fine in practice.

What the proposal does is turning the common cheat into an 
official part of the language, a best practice even. And the 
syntax gets a bit nicer.


More information about the Digitalmars-d mailing list