Question: During debug mode or while I am doing testing, I need to print lots of various information, so i use this method:

```
#ifdef TESTING
// code with lots of debugging info
#else
// clean code only
#endif // TESTING`

```

Is this a good method, or is there any other simple and elegant method ?

But this way, I am repeating the same code in two places and if anything is to be changed later on in the code, I have to do it in both places, which is time consuming and error prone.

Thanks.

I am using MS Visual Studio.

Answer: 
You could use a macro to print debug information and then in the release build, define that macro as empty.

e.g.,

```
#ifdef _DEBUG
#define DEBUG_PRINT(x) printf(x);
#else
#define DEBUG_PRINT(x)
#endif

```

Using this method, you can also add more information like

```
__LINE__ 
__FILE__

```

to the debug information automatically.
Use a define like that on include headers

```
#ifdef  TESTING
#define DEBUG_INFOS(_X_) CallYourDebugFunction(_X_ )
#else
#define DEBUG_INFOS(_X_) ((void)0)
#endif

```

and then use only this on your code

```
...
DEBUG_INFOS("infos what ever");
RestOfWork();
...

```

You can also use and search for the **ASSERT** and **TRACE** macros and use the **DebugView** from sysinternals to read the output real time from trace, or track problems with the ASSERT. ASSERT and TRACE do similar work, and you can get ideas from them.

comments: I use the TESTING declare, because I see that on the question.