Singular or plural for enumerations?

后端 未结 7 1670
长发绾君心
长发绾君心 2021-01-31 12:56

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

enum Weekdays
{
    Monday,
    Tuesday,
    Wednesday         


        
7条回答
  •  清酒与你
    2021-01-31 13:38

    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?

提交回复
热议问题