I have this C code that implements an algorithm in the context of computer science research. The mentioned code contains many printf
and other functions calls that output formatted information about the state of the algorithm and key values in particular points. This output is very useful/clear from a learning perspective.
I would like to somehow preserve and access this information if desired, but not hurting the performance if I don't want such information.
I thought about some DEBUG
macro definition, and injected a bunch of ifdef
s:
#define DEBUG
...
#ifdef DEBUG
printf("At this point...");
#endif
But this makes the code ugly and difficult to read.
I am using Git, so perhaps some sort of alternate version could be a better approach to access the "learning" or "clean" version of the code.
So my concrete questions are related with practicality and coding conventions:
- Is there a practical way to accomplish this?
- Is this just a flat out bad practice, and I shouldn't keep code doing this sort of thing?