Demystifying Common Casings in Programming: What They Are and When to Use Them
Naming things when programming can be challenging, especially for me as I always try to do it as well as possible. For this reason, I thought of collecting the information from multiple references about this in an article for myself and for those who are interested. So, in the following, I will explain the differences between the most widely used types of casings in programming, along with examples of their uses.
But first, let’s answer the question: Why should we use casing in programming?
The answer is relatively simple: In programming, spaces are reserved characters.
For example, you cannot do the following:
first name = "Mohammad"
Besides that, using casing in programming promotes readability, consistency, interoperability, and code portability.
Common Casings Types in Programming:
Camel Case:
Camel case starts with a lowercase letter and the first letter of every new subsequent word has its first letter capitalized and is compounded with the previous word.
Use: It is often used in the declaration of variables and functions name.
Example:
firstName = "Mohammad"
lastName = "Shahnazi"
myFunction()
onCreate()
isNight()
Pascal Case:
Pascal case is similar to camel case, with the only difference being that pascal case requires the first letter of the first word to also be capitalized.
Use: It is often used as a convention in declaring classes in many programming languages.
Example:
MyClass()
MainActivity()
Toast()
Snake Case:
Snake case combines words by replacing each space with an underscore and lowercasing all the words.
Use: Most used in Python to declare functions and variables.
Example:
python_function()
In the all caps version that is used to declare constants, all letters are capitalized and it is called CONSTANT_CASE.
Kebab Case:
Kebab case is like snake case but instead of underscore, the dash is used, it combines words by replacing each space with a dash.
Use: Mostly used in URLs.
Example:
https://appdevtools.com/case-converter
Also, if the first letter of words is capitalized, it is also called Header-Case.
Conclusion
In conclusion, I hope you found this article helpful and that you understand the differences between the casing types in programming and where they are commonly used.
😊 This is my first article on Medium. Thanks for reading!