#if DEBUG vs if (env.IsDevelopment())

Preprocessor directives are conditionally compiled…

Which means that something like this:

#if DEBUG
    //Do something
#endif

Will only be compiled and checked if the DEBUG symbol is defined (it is defined when the build is set to DEBUG). Additionally, in the IDE the code between the preprocessor symbols will appear greyed out.

This code:

if (env.IsDevelopment())
{
    //Do something
}

Is compiled for both release/debug environments. The key here is that the code exists and the tests are run regardless of the environment being debug/release. In more complicated scenarios this has two effects:

  • The execution of the code may be slower
  • The executable will be larger

Additionally including debug code in a release environment may be giving away some trade secrets or other vital information if released. Where possible try to avoid releasing debug code in release mode.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)