Skip to content

Comments

Split numbers embedded in non-snake-case words#2

Open
D-Walther wants to merge 1 commit intomasterfrom
proposal-number-split-improvement
Open

Split numbers embedded in non-snake-case words#2
D-Walther wants to merge 1 commit intomasterfrom
proposal-number-split-improvement

Conversation

@D-Walther
Copy link
Owner

@D-Walther D-Walther commented Sep 5, 2025

Reasoning:

  • Numbers in camelCase (e.g. camelCase123) in C are usually translated to defines by splitting them first (e.g. BYTE_SIZE_CAMEL_CASE_123). In this case, splitting numbers from letters makes sense.
  • This split is not always sensible however. If a message is named MyMessage_mk2, the user has implicitly expressed that "mk" and "2" belong together, making "BYTE_SIZE_MY_MESSAGE_MK_2" an unintuitive result. An underscore in a word can therefore be interpreted as the user taking charge of the process; we should not interfere. Hence the "_" in word condition.
  • This alone can result in inconsistencies in places where "UPPER_SNAKE_CASE" is used, however (e.g. in case of enum values and constants). If an enum value named "TI82_PLUS" results in "ti82_plus", "TI82" should not result in "ti_82". To remedy this, I've also excluded uppercase words.

In other words: if the user breaks convention, assume they have a reason for it. This includes:

  • underscore in PascalCase or camelCase (e.g. MyMessage_v1, myMessage_v1 -> my_message_v1)
  • numbers next to words in snake_case and UPPER_CASE (e.g. my_value1, MY_VALUE1 -> my_value_v1)

Reasoning:
- Numbers in camelCase (e.g. camelCase123) in C are usually translated to defines by splitting them first (e.g. BYTE_SIZE_CAMEL_CASE_123).
- This split is not always sensible however. If a message is named MyMessage_mk2, the user has implicitly expressed that "mk" and "2" belong together, making "BYTE_SIZE_MY_MESSAGE_MK_2" an unintuitive result. An underscore can therefore be treated as an explicit choice.
- This alone can result in inconsistencies in places where "UPPER_SNAKE_CASE" is used (e.g. enum values and constants).  If an enum value named "TI82_PLUS" results in "ti82_plus", "TI82" should not result in "ti_82". Therefore, uppercase words should also be exempt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant