@trusted AKA most useless statement ever

Stefan Koch via Digitalmars-d digitalmars-d at puremagic.com
Fri Nov 25 02:19:53 PST 2016


On Friday, 25 November 2016 at 10:14:46 UTC, Satoshi wrote:
> Simply, it should be replaced by:
>
> void safeFunc() @safe {
>     unsafe {
>         auto vi = doUnsafeCall();
>     }
> }
>
> @trusted functions are prohibited by d-idiom (so I don't know 
> why are still in D).
> So, when I need to create a simple window with OpenGL context I 
> need to write about 10-15 calls to system functions. But 
> D-idiom[1] for @trusted tells me to make @trusted functions as 
> small as possible. OK, it makes sense.
>
> but writing 20 times something like:
> auto vi = (() @trusted => glXChooseXFBConfig(...))();
>
> or:
> auto vi = () @trusted { return glXChooseXFBConfig(...); }();
>
> is annoying and just forced me to mark whole class with 
> @trusted...
>
>
>
> [1] 
> https://dlang.org/blog/2016/09/28/how-to-write-trusted-code-in-d/
Encapsulate the function in a trusted wrapper if otfen.
Or simply not mark code that mucks with opengl as safe.
Because it is not.


More information about the Digitalmars-d mailing list