In programming, we often remove the spaces between words because programs of different sorts reserve the space (‘ ’) character for special purposes. Because the space character is reserved, we cannot use it to represent a concept that we express in our human language with multiple words.
As an example, the concept of user login count is not referenced in our code as user login count often. We do not do the following:
user login count = 5
A typical language parse would treat each word as a separate concept. User, login, and count would each be treated as separate things. So, we do something like the following:
userLoginCount = 5
Now, the parser will see one concept, userLoginCount, and us programmers can easily see the representation.
There is no best way to combine words. In the above example, we removed spaces and capitalized each word following the first word. There are, however, a great number of algorithms for combining words, and a few very common ones.
The most common case types:
camelCase must (1) start with a lowercase letter and (2) the first letter of every new subsequent word has its first letter capitalized and is compounded with the previous word. An example of camel case of the variable camel case var is camelCaseVar.Fun fact: Sort of cameCaSes are often used to EnCrypt a Random tExt and hide a password in The text.
thisTextIsEntirelyInCamelCase
snake_case is as simple as replacing all spaces with a "_" and lowercasing all the words. It's possible to snake_case and mix camelCase and PascalCase but imo, that ultimately defeats the purpose.
An example of snake case of the variable snake case var is snake_case_var.
this_text_is_entirely_in_snake_case
kebab-case is as simple as replacing all spaces with a "-" and lowercasing all the words. It's possible to kebab-case and mix camelCase and PascalCase but that ultimately defeats the purpose.
An example of kebab case of the variable kebab case var is kebab-case-var.this-text-is-entirely-in.kebab-case
PascalCase has every word starts with an uppercase letter (unlike camelCase in that the first word starts with a lowercase letter).
An example of pascal case of the variable pascal case var is PascalCaseVar. Note: It's common to see this confused for camel case, but it's a separate case type altogether.TthisTextIsEntirelyInPascalCase
UPPER_CASE_SNAKE_CASE is replacing all the spaces with a "_" and converting all the letters to capitals.
an example of upper case snake case of the variable upper case snake case var is UPPER_CASE_SNAKE_CASE_VAR.THIS_TEXT_IS_ENTERLY_IN_UPPERCASE_SNAKE_CASE
| Case Type | Example |
|---|---|
| Original Variable as String | some awesome var |
| Camel Case | someAwesomeVar |
| Snake Case | some_awesome_var |
| Kebab Case | some-awesome-var |
| Pascal Case | SomeAwesomeVar |
| Upper Case Snake Case | SOME_AWESOME_VAR |