Singular or plural for enumerations?

Coding StyleEnumeration

Coding Style Problem Overview


Do you use singular or plural for enumerations? I think it makes best sense with plural in the declaration

enum Weekdays
{
    Monday,
    Tuesday,
    Wednesday,
    Thursday,
    Friday,
    Saturday,
    Sunday
}

... but I think it makes more sense with singular when using the type, e.g.

Weekday firstDayOfWeek = Weekday.Monday;

I read a recommendation somewhere to use singular whith regular enums and plural with flags, but I would like to hear some more pros and cons.

Coding Style Solutions


Solution 1 - Coding Style

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.

Solution 2 - Coding Style

One recommendation comes from the .NET Framework Design Guidelines, page 59-60:

> Do use a singular type name for an enumeration, unless its values are bit > fields. > public enum ConsoleColor { Black, Blue, Cyan, ... > Do use a plural type name for an enumeration with bit fields as values, also called a flags enum. > [Flags] public enum ConsoleModifiers { Alt, Control, Shift }

Solution 3 - Coding Style

In the .NET Framework, most "normal" enums (e.g. DayOfWeek) have singular names and flag enums (e.g. StringSplitOptions, BindingFlags) have plural names. It makes sense, since a value of a flag enum can represent multiple items but for a non-flag enum, it can only represent a single item.

Solution 4 - Coding Style

>In general, I consider an enum definition to be a type definition, with the values of the > enum being the different values the type can have; therefore it gets a singular name: > enum Weekday { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }; > enum CoffeeSize { SMALL, MEDIUM, LARGE };

Yes. If you do the mental experience of implementing the enums as classes, then the fact that you'd use a singular name for the type should reveal that it makes sense to use singular names for such enums . E.g.,

struct Weekday {};

const Weekday SUNDAY;
const Weekday MONDAY;
const Weekday TUESDAY;

...

void func (Weekday *day)
{
   if (day == &SUNDAY)
       ...
}

For who prefers plurals in enums, would you name that struct Weekdays?

Solution 5 - Coding Style

In general, I consider an enum definition to be a type definition, with the values of the enum being the different values the type can have; therefore it gets a singular name:

enum Weekday { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };

enum CoffeeSize { SMALL, MEDIUM, LARGE };

Solution 6 - Coding Style

Microsoft recommends using a singular name for enumerations unless it uses the Flags attribute. And as taken from the Framework Design Guidelines book you should not suffix enumeration type names with Enum, Flags, etc. and you should not prefix enumeration values with an abbreviation or acronym as was common with VB enumerations back in the day.

Solution 7 - Coding Style

It's subjective and doesn't matter what you use, as long as you're consistent (personally I use singular as its a carry over from my Sql conventions)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJan AagaardView Question on Stackoverflow
Solution 1 - Coding StyleMatt RuweView Answer on Stackoverflow
Solution 2 - Coding StyleMichael PetrottaView Answer on Stackoverflow
Solution 3 - Coding StylemmxView Answer on Stackoverflow
Solution 4 - Coding StylePedro AlvesView Answer on Stackoverflow
Solution 5 - Coding StyleAviView Answer on Stackoverflow
Solution 6 - Coding StyleBrian GideonView Answer on Stackoverflow
Solution 7 - Coding StyleJaimal ChohanView Answer on Stackoverflow