Encapsulating trust

Daniel Murphy via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 2 10:11:13 PDT 2014


"Dmitry Olshansky"  wrote in message news:lu4iup$l9v$1 at digitalmars.com...
> >
> >    void main() @safe {
> >       char[] msg = "Hello!".dup;
> >       char[] msg2 = msg;
> >
> >       void checkEquals(const char[] msg, const char[] msg2) pure 
> > @trusted {
> >         assert(msg.length == msg2.length);
> >         assert(memcmp(msg.ptr, msg2.ptr, msg.length) == 0);
> >       }
> >
>
> So you think adding boilerplate will make function more easily verifiable? 
> Time and statistics proven that more LOCs ==> more bugs.

Yes, that function is more easily verifiable for @safety, because any 
violation _must_ be inside the @trusted function.  If the @safe violating 
helpers were used, main would effectively be @trusted and more lines would 
need to be reviewed.

> Especially highly repetitive patterns, because nobody actually reads them.

If you have highly repetitive patterns, they should be factored out into 
reusable functions just like always. 



More information about the Digitalmars-d mailing list