Using IDE’s debugging becomes very long in some projects, specially when working with graphics, so sometimes I use debugging code, which prints out values, depending on the environment, sometimes on the project itself and sometimes on the console. But when the project is done, it becomes difficult to find the debugging code, and remove it, and when an unwanted thing pops, it appears odd. I am still a student so its better to learn now then later, how to manage it?
I couldn’t find the proper answer upon searching, but I have a few things in mind:
-
Remove the code as soon as a module is tested, so there is less to find. It works but when the modules have to be tested later (at a higher level) it has top be added again, not to the extent of what was removed but still.
-
Surround it with
ifto make sure it only runs whendebuggingflag is true, and keep it in the final version of the project. -
Plan the debugging code with the project, keep the methods and classes separate (where possible) and erase the calls and objects and when things are done.
What is the proper way of managing it?
The easiest way is to use a
debuggingflag.If this flag is a compiler constant (or otherwise hard-coded) you will need to re-compile the project if you want/do not want debugging.
A better way is to make the flag use a value from a config file/command line parameter — this way you can control debugging without having to re-compile the project.
An even better approach is to use a powerful logging library (if one is available) and use its facilities — the advantage is that you can better fine-tune what you want to log, where and in what format