0

By default, VS puts the compiler directives at the beginning of the line:

    public ServiceStatus IsServiceAvailable(string author, string reader, string deliveryWay)
    {          
#if(DEBUG)
        return ServiceStatus.Available;
#else
        return m_channel.IsServiceAvailableForReceiver(author, reader, deliveryWay);
#endif
    }

Is there a reason why it isnt aligned like this by default?

    public ServiceStatus IsServiceAvailable(string author, string reader, string deliveryWay)
    {          
        #if(DEBUG)
             return ServiceStatus.Available;
        #else
             return m_channel.IsServiceAvailableForReceiver(author, reader, deliveryWay);
        #endif
    }
Jannik
  • 2,310
  • 6
  • 32
  • 61
  • 2
    [Here](http://codereview.stackexchange.com/questions/45482/is-indentation-of-if-endif-directives-an-important-readability-convention) you find a discussion about this subject. – diiN__________ Mar 15 '16 at 10:34
  • Maybe because ancient c compilers [required it to start at the beginning of the line](http://stackoverflow.com/q/789073/33499), and developers were used to it? – wimh Mar 15 '16 at 10:43

1 Answers1

1

I would think because it's logically a separate pre-processing step (it follows similar semantics as C's preprocessor, which is a standalone program). In a sense it's not part of C# proper; it's orthogonal to the actual language features. For example, the preprocessor directives don't have to be in the same block, so they can be used to combine two functions to one, etc.

Because they are coarse tools breaking normal source code flow they are positioned at column 1 in order to make them stand out. This may not be a one-fits all -- if they are used to choose between two variations of a few lines of code inside a function they are used more in the sense of a run time condition, but without the run-time cost. In that case it makes sense to align it with the block indentation.

Peter - Reinstate Monica
  • 15,048
  • 4
  • 37
  • 62