Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Style enums properly. #214

Open
Tracked by #220
luckytyphlosion opened this issue Aug 17, 2023 · 4 comments
Open
Tracked by #220

Style enums properly. #214

luckytyphlosion opened this issue Aug 17, 2023 · 4 comments
Labels

Comments

@luckytyphlosion
Copy link
Member

luckytyphlosion commented Aug 17, 2023

There is no consensus whether enums are enums or typedefs.

Case 1: enums are enums, not typedefs

Do not typedef enums

Good:

enum RTC_TimeOfDay {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
};

Bad:

  • Using a typedef
typedef enum RTC_TimeOfDay {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
} RTC_TimeOfDay;

There is no consensus of the casing of enums (when enums are enums and not typedefs).

Option 1: PascalCase

enum RTC_TimeOfDay {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
};

Option 2: alllowercase_t (similar to primitive non-unit typedefs)
Note: Primitive unit typedefs are u8, u16, u32, s8, s16, s32 etc....

enum rtc_timeofday_t {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
};

Reference all enums with enum in code (this is forced anyway)

Good:

enum RTC_TimeOfDay GF_RTC_GetTimeOfDay(void) {
    RTCTime time;
    GF_RTC_CopyTime(&time);
    return GF_RTC_GetTimeOfDayByHour(time.hour);
}
enum rtc_timeofday_t GF_RTC_GetTimeOfDay(void) {
    RTCTime time;
    GF_RTC_CopyTime(&time);
    return GF_RTC_GetTimeOfDayByHour(time.hour);
}

Bad (doesn't compile anyway):

RTC_TimeOfDay GF_RTC_GetTimeOfDay(void) {
    RTCTime time;
    GF_RTC_CopyTime(&time);
    return GF_RTC_GetTimeOfDayByHour(time.hour);
}
rtc_timeofday_t GF_RTC_GetTimeOfDay(void) {
    RTCTime time;
    GF_RTC_CopyTime(&time);
    return GF_RTC_GetTimeOfDayByHour(time.hour);
}

Case 2: enums are typedefs

Enum casing should be alllowercase_t

Good:

typedef enum rtc_timeofday_t {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
} rtc_timeofday_t;

Bad:

typedef enum RTC_TimeOfDay {
    RTC_TIMEOFDAY_MORN = 0,
    RTC_TIMEOFDAY_DAY,
    RTC_TIMEOFDAY_EVE,
    RTC_TIMEOFDAY_NITE,
    RTC_TIMEOFDAY_LATE,
} RTC_TimeOfDay;

Follow points 1, 2, and 3 of issue #212 (covers typedef struct naming) for the rest of the info

@red031000
Copy link
Member

this was actually agreed, I just havent updated the style guide yet, because im lazy and busy

do not typedef enums, refer explicitly to them, PascalCase

@tgsm
Copy link
Collaborator

tgsm commented Aug 19, 2023

No typedef, PascalCase

Copy link

This issue has had no activity for 60 days and will be marked stale. If there is no further activity, it will be closed in 30 days.

Copy link

This issue has had no activity for 60 days and will be marked stale. If there is no further activity, it will be closed in 30 days.

@github-actions github-actions bot added the stale label Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants