pret / pokeheartgold

Decompilation of Pokemon HeartGold/SoulSilver
350 stars 109 forks source link

Style enums properly. #214

Open luckytyphlosion opened 1 year ago

luckytyphlosion commented 1 year ago

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:

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 commented 1 year ago

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 commented 1 year ago

No typedef, PascalCase

github-actions[bot] commented 3 months ago

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[bot] commented 3 weeks ago

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.