Disallow side effects in assert
Marco Leise
Marco.Leise at gmx.de
Tue Feb 4 09:45:27 PST 2014
Am Tue, 04 Feb 2014 14:25:14 +0000
schrieb "bearophile" <bearophileHUGS at lycos.com>:
> An example of the problem?
>
> http://forum.dlang.org/thread/52EFE127.8070504@yahoo.com?page=2#post-xodootdnxopfyeqmhnjb:40forum.dlang.org
>
> Bye,
> bearophile
Yes, this is definitely why asserts should not have side
effects when they succeed. I think maybe the earlier try_lock
example could be written more cleanly as:
assert(lock.is_locked);
Still this requires is_locked to be "strongly pure", which
cannot be expressed explicitly in D. (Otherwise it could
change the implicit this and cause a side-effect.)
--
Marco
More information about the Digitalmars-d
mailing list