In any programming language, naming conventions are a very important best practice to follow. Different parts of a program are written in specific cases so they can communicate easily their purpose in the source code.
This short article lists some popular casings such as camel case, pascal case, snake case, and kebab case along with a few other casings with respective examples. We also will compare these cases to understand which one to use in which case, generally.
Casing Style | Example | Characteristics | When to Use? |
---|---|---|---|
Camel Case | camelCaseExample | The first word starts in lowercase, and then all words capitalized | method names, variable names in Java |
Pascal Case | PascalCaseExample | All words capitalized | class names, interface names in Java |
Snake Case | snake_case_example | Words (in lowercase) separated by underscores | method names, variable names in Python |
Kebab Case | kebab-case-example | Words (in lowercase) separated by hyphens | URLs, file names, and CSS class names |
Upper Snake Case / Screaming Snake Case | SCREAMING_SNAKE_CASE_EXAMPLE | Words (in UPPERCASE) separated by underscores | Constants |
Upper Kebab Case / Screaming Kebab Case | UPPER-KEBAB-CASE-EXAMPLE | Words (in UPPERCASE) separated by hyphens | Similar to kebab case but with uppercase letters |
Let us understand each case in more detail.
1. Camel Case
Camel case is characterized by having the first word lowercase and subsequent words capitalized. The words are written without any separators between words. Camelcase is commonly used for naming variables and method names in programming languages like JavaScript, Java, and C#.
- The first word starts with a lowercase letter.
- Subsequent words are capitalized.
- No spaces or punctuation between words.
getItem()
findAtIndex()
calculateTotalAmount()
userId
2. Pascal Case
Pascal case, also known as Upper Camel Case, recommends the first letter of each word to be capitalized, including the first word. There are no spaces or punctuation between words. Pascal case is commonly used for naming classes, interfaces, and types in languages like Java, C#, and TypeScript.
- All words are capitalized.
- No spaces or punctuation between words.
ArrayList
HashMap
WebDriver
3. Snake Case
Snake case is quite popular in Python. It recommends writing the words in lowercase letters and separated by underscores (_). We can use this casing for writing the variables, functions, and file names in Python and other scripting languages.
- Words are written in lowercase letters.
- Words are separated by underscores (_).
data_set
user_id
calculate_total_amount
4. Kebab Case
Kebab case, also known as spinal case or dash case, recommends writing the words in lowercase letters and separated by hyphens (-). It is often used for naming variables, file names, and CSS class names in web development, particularly in HTML, CSS, and JavaScript.
- Words are written in lowercase letters.
- Words are separated by hyphens (-).
div-height-css
span-id
calculate-total-amount
5. Screaming Snake Case
In Screaming Snake Case, all letters are in uppercase and the words are separated by underscores (_). It is commonly used for constants or configuration variables in programming languages such as Java and C#.
- Words are written in uppercase letters.
- Words are separated by underscores (_).
MY_ERROR_CODE
MY_CONSTANT_NAME
6. Screaming Kebab Case
The screaming kebab casing requires to write all the words in uppercase letters and separated by hyphens (-). Similar to the screaming snake case, this casing is also used for constants but in environments where hyphens are preferred over underscores.
- Words are written in uppercase letters.
- Words are separated by hyphens (-).
UPPER-KEBAB-CASE-EXAMPLE
MY-VARIABLE-NAME
CALCULATE-TOTAL-AMOUNT
7. Conclusion
This short tutorial discussed some popular casings used in programming languages. We discussed what these casings look like, and their characteristics with examples. We also learned when to use which casing in a programming language, as a general best practice.
Happy Learning !!
Comments