✔️ DO use a singular type name for an enumeration unless its values are bit fields. ✔️ 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. ❌ DO NOT use "Flag" or "Flags" suffixes in enum type names.
Defining an Enum The swift naming convention for enums is the same as a class or struct (camel case with the first letter capitalised). The name of the enum should always be the singular reference to what your defining, not the plural; for example, use Device instead of Devices .
Enumerations make for clearer and more readable code, particularly when meaningful names are used. The benefits of using enumerations include: Reduces errors caused by transposing or mistyping numbers. Makes it easy to change values in the future.
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. Cheers!
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.
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 }
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.
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
?
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 };
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.
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