On 02/15/2010 05:37 PM, Pelle Månsson wrote:
On 02/15/2010 10:53 PM, sybrandy wrote:
In short: I'm using mixins so that the person who's using the library
doesn't have to put in version(DoLogging)... all over the place. By
containing it in one location, I was trying to keep the code using the
library cleaner.
void trace(string s) {
version (NoTrace) {
//do nothing
} else {
//do tracing
}
}
trace("Stuff");
will this not work?
It will work, however I was going for "if you're not logging, why have
the logging code in there?" Like I said, I was going for performance
and with mixins I could ensure there was no runtime overhead with
instantiating the class, setting up the logger, etc. when the user
turned logging off.
In this version:
template Trace(string msg)
{
version (NoLogging)
{
}
else
{
// Write to the log file...
}
}
If NoLogging is turned on, then no code to perform the logging is even
added to the file. It seemed to me that this was favorable to having a
bunch of empty functions laying around. Now, if DMD was smart enough to
eliminate empty functions, that would be great and I wouldn't have to do
this.
Regardless, I'm still all for moving the "mixin" keyword to the mixin
declaration vs. where it's instantiated.