Since we cannot define a variable like
fruits in basket because many (or maybe all) programming languages will interpret the space character as the end of the identifier and the beginning of something else, we need to do something like
Camel, pascal, kebab and snake case (and others) are all naming conventions that we use in computer programming to be able to create compound names for variables, types, functions, clases and other structures in source code.
The rules are that we capitalize all the words after the first one.
|fruits in basket||fruitsInBasket|
Here we need to capitalize all the words including the first one.
|fruits in basket||fruitsInBasket||FruitsInBasket|
PascalCase is often preferred by C programmers.
For this one, we add a dash between each word and all of them are lowercase.
|fruits in basket||fruitsInBasket||FruitsInBasket||fruits-in-basket|
HTML5 attributes can start with
data-name. Also, CSS uses dashes in property-names like background-color.
In contrast to the kebab case, for the snake case we add an underscore instead.
|fruits in basket||fruitsInBasket||FruitsInBasket||fruits-in-basket||fruits_in_basket|
Many programmers use underscores especially in SQL databases for things like
Some benefits that naming conventions bring are:
- Consistency. Since naming something is one of the hardest jobs of a programmer, at least we can agree on a convention and be consistent about it.
- Better understanding. Compound names explain a lot better than one word or one character the purpose of the structure.
- Readability. Enhances the ability to read the code.
- Automation. Enables the use of automated refactoring and search and replace tools.