Debugging – Should Debug Code Be Left in Place or Removed After Fixing Bugs?

debugging

I, for one, only add debug code (such as print statements) when I'm trying to locate a bug. And once I've found it, I remove the debug code (and add a test case which specifically tests for that bug). I feel that it's cluttering the real code and therefore has no place there unless I'm debugging.

How do you do it? Do you leave the debug code in place, or remove it when obsolete (which may be difficult to judge when that is)?

Best Answer

Debug print statements should be taken out; however, if you're needing to add them to debug a production problem then it may be worth considering if you have enough information being put into your logging framework. Information about parameters, error conditions and so on may well be useful later on when the next bug appears. Using a good logging framework that can be have debug or tracing log messages turned on dynamically can be very useful in the wild.

Related Topic