The guidelines are clear for enumerations...
Do use a singular name for an enumeration, unless its values are bit fields.
(Source: http://msdn.microsoft.com/en-us/library/ms229040.aspx)
...but not so clear for a class of constants (or read-only static fields/propertes). For example, should the name of this class be singular or plural?
public static class Token // or Tokens?
{
public const string Foo = "Foo";
public const string Bar = "Bar";
public const string Doo = "Doo";
public const string Hicky = "Hicky";
}
Constants should be written in uppercase characters separated by underscores. Constant names may also contain digits if appropriate, but not as the first character.
Class names should be nouns, in mixed case with the first letter of each internal word capitalized. Try to keep your class names simple and descriptive. Use whole words-avoid acronyms and abbreviations (unless the abbreviation is much more widely used than the long form, such as URL or HTML).
Rules for naming a variableA variable name can only have letters (both uppercase and lowercase letters), digits and underscore. The first letter of a variable should be either a letter or an underscore. There is no rule on how long a variable name (identifier) can be.
Classic C doesn't use camel-case; I've written code in camel-case in C, and it looks weird (so I don't do it like that any more). That said, it isn't wrong - and consistency is more important than which convention is used.
I would use the plural: Tokens
. This implies that the static class is serving as a collection of items of some sort (whose runtime types are not that of the class).
On the other hand, an enumeration's fields are instances of the enumeration type. For example, TypeCode.String
is a TypeCode
. It would be weird to say that TypeCodes.String
is a TypeCodes
.
However, in your Tokens
example, using the singular gives us Token.Foo
, which is a token, but it is not a Token
(it is a string
).
(Or, if you use the plural class name, Tokens.Foo
is a string
, not a Tokens
. Ack!)
Since both are used essentially the same way, and are conceptually the same thing, I'd recommend just following the enum guidelines.
I don't have any official naming standard to link to, but I can tell you what I would do.
I would use the plural name: Tokens
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With