Temporarily disable all purity for debug prints
spir
denis.spir at gmail.com
Tue Apr 12 14:54:02 PDT 2011
On 04/12/2011 09:54 PM, Steven Schveighoffer wrote:
> 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.
Also naughtily:
pure void foo(n) {
writeln(iPerformSideEffect(n), " ...in foo");
return n+1;
}
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list