Call dependent on boolean

What technique do you prefer?


define('DEBUG') = true; // or read from config, does not matter
...
if (DEBUG)
   log(....);
...

function log(....) {
   ... // logging
}

OR

define('DEBUG') = true;
...
log(....);

function log(...) {
   if (DEBUG) return false;
   ... // logging
}

(Obviously, this is not about functions vs. methods …)

Hi…

Well yes ;). The thing is, I think you are going about it counter productively. Cluttering the code will create more bugs, not less.

If you have a staging/test environment that is a genuine clone of the live one (use a VM if necessary), then you can bring to bear advanced debugging techniques. In my case…er…print statements. Picking out log debug statements is incredibly labour intensive. Reproduce the bug in a controlled environment.

I would say get the patient to the doctor rather than have them telephoning every symptom constantly. Quality of life will be improved.

Preventative medicine is another story…

yours, Marcus

Personally?

I’d use a logging object. The log function would log it if needs be, but I certainly wouldn’t make debug a constant, rather a private property.

That way you can turn off logging in certain parts of an application, or turn it on for one specific area.

None of the above, logging is a quintessential example of cross cutting concerns. :stuck_out_tongue:

Cheers,
Alex

First, considering log conditions may change based on the function, procedure, etc. Although, if you don’t anticipate ever needing to change it than the second is probably the best choice. I just prefer to anticipate change/modification so it doesn’t come around and bite me later.

Marcus: Hey, I do not plan anything, these creatures simply peep out and derange …

Marcus,

Thanks for ruining my desktop. You’ve just made me snort coffee all over it :rofl:

Hi…

Why are you planning to have so many bugs?

yours, Marcus

Second one. Less repeated code. Of course if (DEBUG) really isn’t the best solution to debugging.