Temporarily disable all purity for debug prints
bearophile
bearophileHUGS at lycos.com
Fri Apr 15 19:06:28 PDT 2011
Walter:
> On the contrary, I think it is the right solution. After all, the reason people
> want to put impure code in a pure function is for debugging. By putting it under
> the debug conditional, any logging or printing code can be there without needing
> the compiler to be aware of what they do.
(Extra note: logging not fully related to debugging. Large programs often keep logs even in release mode.)
There is something I don't understand. If your last change allows code like this, isn't it breaking the safety of pure functions in debug mode? Do you think this loss of safety is not important?
int some_global;
void loggit(int x) {
some_global++;
writeln(x);
}
pure nothrow int sqr(in int x) {
debug loggit(x);
return x * x;
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list