130

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.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Jan Aagaard
  • 10,940
  • 8
  • 45
  • 80

7 Answers7

126

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.

Matt Ruwe
  • 3,386
  • 6
  • 39
  • 77
  • 1
    With the note that bit fields should be pluralized. – sourcenouveau Aug 20 '10 at 15:48
  • 3
    Here is the latest version of the MSDN Guidelines for Enumeration Design: http://msdn.microsoft.com/en-us/library/ms229058.aspx – Rodney S. Foley Jun 07 '12 at 20:57
  • One book I am very thankful that I've read is the [Framework Design Guidelines](https://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321545613). Basically it's written by 15+ authors who all played large roles in the development of .NET framework over the years. The book gives you an insight into their thought process when they develop the framework APIs, and in doing so makes you borderline clairvoyant when it comes to navigating any Microsoft framework, toolkit, etc. Many if not all of the text can be found in their docs website, but this packages it up very nicely. – Ross Brasseaux Jun 15 '20 at 22:49
41

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
}
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
  • Yes I like the idea, but... what would sound better, if I wanted to define a set of modifiers? (dart language example) (1) final modifiers = {ConsoleModifiers.Alt, ConsoleModifiers.Control}, or (2) final modifiers = {ConsoleModifier.Alt, ConsoleModifier.Control} ? All in all, I would prefer always singular. – Giorgio Barchiesi Aug 25 '23 at 06:19
17

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.

Mehrdad Afshari
  • 414,610
  • 91
  • 852
  • 789
6

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?

Grzegorz Rożniecki
  • 27,415
  • 11
  • 90
  • 112
Pedro Alves
  • 1
  • 1
  • 1
4

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.

Brian Gideon
  • 47,849
  • 13
  • 107
  • 150
  • But is there actually a reason why? We prefix interfaces with 'I'. Why not prefix enums with 'E' and flags with 'F'. That would make it crystal clear. Note that I do not like prefixing anything else, but these are special cases like interface where the type will never change. –  Sep 07 '09 at 20:10
2

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 };
Avi
  • 19,934
  • 4
  • 57
  • 70
0

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)

Jaimal Chohan
  • 8,530
  • 6
  • 43
  • 64
  • 20
    It does matter. Conventions promote readability and maintainability. Personal consistency does not compare to conventional consistency. – grenade Aug 26 '09 at 16:38
  • 2
    Hard to be consistent if each library has their own "subjective" opinion. – Paul Biggar Aug 26 '09 at 16:38
  • 1
    I guess as Microsoft says use singular, we should ALL use singular. Nope. As long as you're consistent with your plualization and singularization (?), it really doesn't matter. – Jaimal Chohan Aug 26 '09 at 16:46