Most common programming string case styles
While coding, we can't use space as a word seperator for variable names or so because the parser will consider each word as a seperate entity. Hence we follow different strategies to combine words. However, there are so many algorithms available to combine words. In this post, let's see some of the most commonly used String case style strategies for combining words.
- camelCase
- PascalCase
- snake_case
- kebab-case
1. camelCase
Camel case combines words by removing spaces and by making the first letter of each word as Capital from second word onwards. Please note that the firstword first letter will be in lower case. This style is often used as convention to declare variables in many languages.
Example
Raw: user first name
camelCase: userFirstName
2. PascalCase
Pascal case combines words by removing spaces and by making the first letter of each word as Capital even the first word. This style is more often in declaring class names in many languages.
Example
Raw: user first name
Pascal Case: UserFirstName
3. snake_case
Snake case combines words by replacing each white space with an underscore (_) and all letters are capitalized in all caps version. This style in all caps version is more often in declaring constants in many languages and lower cased version is often used in declaring database field names.
Example
Raw: user first name
Snake_Case: user_first_name
Snake_Case(all caps version): USER_FIRST_NAME
4. kebab-case
Kebab case combines words by replacing each white space with a hyphen (-). This style is more often used in URLs.
Example
Raw: user first name
Kebab-case: user-first-name
Are you wondering which style is best to adopt while writing code?
There is no best method and it is developer's choice to use. One main thing is follow consistency through out your application which makes it easy to follow as a team to be consistent and increases readability.