views:

46

answers:

1

As stated in the framework design guidelines and the WWW in general, the current guideline is to name your constants like this

LastTemplateIndex
as opposed to
LAST_TEMPLATE_INDEX

With the PascalCasing approach, how do you differentiate between a Property and a Constant.
ErrorCodes.ServerDown is fine. But what about private constants within your class ? I use quite a lot of them for naming magic numbers.. or for expected values in my unit tests and so on.

The ALL_CAPS style helps me know that it is a constant .

_testApp.SelectTemplate(LAST_TEMPLATE_INDEX);

*Disclosure: I have been using the SCREAMING_CAPS style for a while for constants + I find it more readable than squishedTogetherPascalCasedName. It actually STANDS_OUT in a block of text*

+2  A: 

We create a seperate static class to put our constants in and label it Constants.

That way when we access a constant it's always Constant.YourConstantHere

so

  class NewClass
    {

        static class Constants
        {
            public const int T = -1;
        }
    }
Kevin
I've done this too for 'global'/'shared' constants - `TestConstants.SampleProjectPath`. However having one of these constant-containers per class that has internal constants seems like a workaround to me.
Gishu
@Gishu I suppose it is a little bit, but it allows us to quickly determine what is a constant and what isn't. Since most people don't like the ALL_CAPS implementation, this an easy way of differentiating between properties and constants for us.
Kevin