Coding Conventions - Naming Enums
Enums are classes and should follow the conventions for classes. Instances of an enum are constants and should follow the conventions for constants. So
enum Fruit {APPLE, ORANGE, BANANA, PEAR};
There is no reason for writing FruitEnum
any more than FruitClass
. You are just wasting four (or five) characters that add no information.
This approach is recommended by and used in the The Java™ Tutorial's examples themselves.
Java Enum Type Coding Convention
I would say that the enum itself, since it's a class, should follow the camel case convention as every class, while the entries of enum, since they are constants, should be upper case with underscore (eg. NOT_EQUAL
).
The version uppercase without underscore is absolutely unreadable, never use it.
Enum Naming Convention - Plural
Microsoft recommends using singular for Enum
s unless the Enum
represents bit fields (use the FlagsAttribute
as well). See Enumeration Type Naming Conventions (a subset of Microsoft's Naming Guidelines).
To respond to your clarification, I see nothing wrong with either of the following:
public enum OrderStatus { Pending, Fulfilled, Error };
public class SomeClass {
public OrderStatus OrderStatus { get; set; }
}
or
public enum OrderStatus { Pending, Fulfilled, Error };
public class SomeClass {
public OrderStatus Status { get; set; }
}
Naming of enums in Java: Singular or Plural?
Enums in Java (and probably enums in general) should be singular. The thinking is that you're not selecting multiple Protocols, but rather one Protocol of the possible choices in the list of values.
Note the absence of plurals: http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
Does the naming convention for ENUMs in C# usually have everything in UPPERCASE?
One should use Pascal case when they are typing enum types and values. This looks like
public enum Ati
{
Two = 0,
Three = 1,
Five = 2,
}
According to Microsoft:
Identifier | Case | Example
--------------------------------------------
Enumeration type | Pascal | ErrorLevel
Enumeration values | Pascal | FatalError
The only thing that you should make all caps like that are constant/final variables.
When you have local variables you should always use camel case.
thisIsCamelCasedVariable = "ya baby";
More about enums: https://msdn.microsoft.com/en-us/library/4x252001(v=vs.71).aspx
More about naming conventions C#: https://msdn.microsoft.com/en-us/library/ms229043%28v=vs.100%29.aspx
Javascript ENUM pattern naming convention
According to Google's coding conventions this is the correct way indeed to name an enum in javascript.
As requested here is a link.
Singular or plural for enumerations?
Here it is straight from Microsoft:
http://msdn.microsoft.com/en-us/library/4x252001(VS.71).aspx
Use a singular name for most Enum
types, but use a plural name for Enum
types that are bit fields.
Related Topics
What Is the Purpose of @Namedarg Annotation in Javafx 8
Swing's Keylistener and Multiple Keys Pressed at the Same Time
Populating Spring @Value During Unit Test
Run a Command Over Ssh with Jsch
Jsf Convertdatetime Renders the Previous Day
How to Access Parameters in a Restful Post Method
Isn't the Size of Character in Java 2 Bytes
Static Fields on a Null Reference in Java
How to Compile & Run Java Program in Another Java Program
Dynamic Graphics Object Painting
Why Does String.Valueof(Null) Throw a Nullpointerexception
What's Up with Java's "%N" in Printf
How to Open a File with the Default Associated Program