Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum Naming Convention - Plural

I'm asking this question despite having read similar but not exactly what I want at C# naming convention for enum and matching property

I found I have a tendency to name enums in plural and then 'use' them as singular, example:

public enum EntityTypes {   Type1, Type2 }  public class SomeClass {   /*     some codes   */    public EntityTypes EntityType {get; set;}  } 

Of course it works and this is my style, but can anyone find potential problem with such convention? I do have an "ugly" naming with the word "Status" though:

public enum OrderStatuses {   Pending, Fulfilled, Error, Blah, Blah }  public class SomeClass {   /*     some codes   */    public OrderStatuses OrderStatus {get; set;}  } 

Additional Info: Maybe my question wasn't clear enough. I often have to think hard when naming the variables of the my defined enum types. I know the best practice, but it doesn't help to ease my job of naming those variables.

I can't possibly expose all my enum properties (say "Status") as "MyStatus".

My question: Can anyone find potential problem with my convention described above? It is NOT about best practice.

Question rephrase:

Well, I guess I should ask the question this way: Can someone come out a good generic way of naming the enum type such that when used, the naming of the enum 'instance' will be pretty straightforward?

like image 982
o.k.w Avatar asked Sep 10 '09 15:09

o.k.w


People also ask

Should enum names be plural?

Use a singular name for most Enum types, but use a plural name for Enum types that are bit fields. With the note that bit fields should be pluralized.

Should enum names be plural Java?

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.

How should enums be named?

Enums are types, so they should be named using UpperCamelCase like classes. The enum values are constants, so they should be named using lowerCamelCase like constants, or ALL_CAPS if your code uses that legacy naming style.

Should enum be plural C#?

Naming Enumerations ✔️ DO use a plural type name for an enumeration with bit fields as values, also called flags enum. ❌ DO NOT use an "Enum" suffix in enum type names.


2 Answers

Microsoft recommends using singular for Enums 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; } } 
like image 105
jason Avatar answered Oct 05 '22 22:10

jason


I started out naming enums in the plural but have since changed to singular. Just seems to make more sense in the context of where they're used.

enum Status { Unknown = 0, Incomplete, Ready }  Status myStatus = Status.Ready; 

Compare to:

Statuses myStatus = Statuses.Ready; 

I find the singular form to sound more natural in context. We are in agreement that when declaring the enum, which happens in one place, we're thinking "this is a group of whatevers", but when using it, presumably in many places, that we're thinking "this is one whatever".

like image 42
Bob Kaufman Avatar answered Oct 05 '22 22:10

Bob Kaufman