On 04/12/2011 09:54 PM, Steven Schveighoffer wrote:
On Tue, 12 Apr 2011 15:48:33 -0400, bearophile <bearophileh...@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

Reply via email to