In a few places in our code we use #if DEBUG blocks to simplify development. Things like:
#if DEBUG
serverIP = localhost;
#else
serverIP = GetSetting()
#endif
or
private bool isLicensed()
#if DEBUG
return true;
#endif
return CheckSetting()
There are also a few places where we make cosmetic changes like this:
#if DEBUG
background = humorousImage.jpg
#else
background = standardColor
#endif
Is it dangerous to depend on #if debug to make development easier? If it is, what is a valid use of #if debug?
It is a really bad idea. If you’re trying to catch a production bug your debug clauses will certainly trip you up at some stage or another. You want to be as close as possible to code that runs in production. In your example you’ll never be able to find a bug in CheckSetting()
By the looks of things your code is too tightly coupled. What you want to be doing is to make modules/classes less dependent on each-other and practice Test Driven Development. Also have a look at Inversion of Control (aka Dependency Injection).
Working Effectively with Legacy Code has some useful insights on how to introduce TDD. It also has some really good pointers on how to do TDD in various scenarios where it might be hard to test things.