Temporarily disable all purity for debug prints
Steven Schveighoffer
schveiguy at yahoo.com
Tue Apr 12 12:54:29 PDT 2011
On Tue, 12 Apr 2011 15:48:33 -0400, bearophile <bearophileHUGS at lycos.com>
wrote:
> Walter:
>
>> pure void foo()
>> {
>> debug writeln("in foo()");
>> }
>>
>> Simple and effective.
>
> Very simple designs are sometimes the mark of the genius. But isn't your
> idea able to lead to debug code that's more buggy than the nondebug
> code, if some side effect (like modifying a global) is used inside a
> debug{}?
Well, yes. So? How does the compiler establish rules to separate "safe
debug printing" from "all code that isn't pure"? If you did that, how
does the compiler know it's safe? The only way I can think of is to treat
writeln specially, which doesn't sound like the right thing to do.
Note also, that the code which outputs a custom object via writeln (either
toString or writeTo) could modify a global.
-Steve
More information about the Digitalmars-d
mailing list