Camel case and snake case: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
m (typo)
Line 4: Line 4:
'''Camel Case'''.
'''Camel Case'''.


'''Snake case''' variables are generally all lower case, with an underscore between words in the variable, as in '''snake_case_variable''''. '''Camel case''' variables are generally lower case first (except in some Pascal conventions or with class names in many other languages), with an underscore between words in the variable, as in ''''snakeCaseVariable''''.
'''Snake case''' variables are generally all lower case, with an underscore between words in the variable, as in '''snake_case_variable''''. '''Camel case''' variables are generally lower case first (except in some Pascal conventions or with class names in many other languages), with captalization of the initial letter of the words within the variable, as in ''''snakeCaseVariable''''.


Leading underscores are not used in such variables except as part of a different naming convention, usually for special internal or system variables. White space is not permitted as part of camel case or snake case variable names.
Leading underscores are not used in such variables except as part of a different naming convention, usually for special internal or system variables. White space is not permitted as part of camel case or snake case variable names.

Revision as of 23:01, 23 November 2021

Camel case and snake case is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Two common conventions for naming of computer program variables are Snake Case and Camel Case.

Snake case variables are generally all lower case, with an underscore between words in the variable, as in snake_case_variable'. Camel case variables are generally lower case first (except in some Pascal conventions or with class names in many other languages), with captalization of the initial letter of the words within the variable, as in 'snakeCaseVariable'.

Leading underscores are not used in such variables except as part of a different naming convention, usually for special internal or system variables. White space is not permitted as part of camel case or snake case variable names.

Task
  • Write two functions, one to change snake case to camel case and one to change camel case to snake case. If possible, generalize the function enough to apply to strings containing spaces between words or a `-` dash between words, assuming that in those cases a space or hyphen is a also a separator character, like `_`, for the purpose of creating a new variable name. Leading or trailing whitespace may be ignored.
  • Show the results on changing to both snake case and camel case for each of the following strings:

<lang java> "snakeCase", "snake_case", "variable_10_case", "variable10Case", "ɛrgo rE tHis", "hurry-up-joe!", "c://my-docs/happy_Flag-Day/12.doc", " spaces " </lang>

Related tasks