Camel case and snake case: Difference between revisions

From Rosetta Code
Content added Content deleted
mNo edit summary
(new task)
Line 2: Line 2:


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


'''Snake case''' variables are generally all lower case, with an underscore between words in the
'''Snake case''' variables are generally all lower case, with an underscore between words in the

Revision as of 22:22, 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 an underscore between words in 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 iin those cases a space or hyphen is a also a separator character, like `_`, for the purpose of creating a new varable 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