Different Casing Convention Styles
What Are Casing Convention Styles?
When naming things in code, you can't write names like in English. This is where casing convention styles come in. Casing conventions allow you to write compound words or phrases to make names more readable and consistent. Casing conventions don't use standard punctuation and follow two things.
- What character, if any, is used instead of a space to separate words?
- How the words are written with uppercase and lowercase characters.
Camel Convention Styles
Camel convention styles don't use a character to separate words. Instead, the separation is done by writing the first letter in the word with an uppercase letter.
Pascal Case
Pascal case, or upper camel case, is written with the first letter of each word in uppercase.
PascalCaseConvention
Camel Case
Camel case is written the same as Pascal case, except the first word doesn't start with an uppercase.
camelCaseConvention
Snake Convention Styles
Snake convention styles use an underscore (_) to separate each word.
Snake Case
Snake case is written with all words in lowercase.
snake_case_convention
Pascal Snake Case
Pascal snake case is written with the same casing as Pascal case.
Pascal_Snake_Case_Convention
Camel Snake Case
Camel snake case is written with the same casing as Camel case.
camel_Snake_Case_Convention
Screaming Snake Case
Screaming snake case or constant case is written with all words in uppercase.
SCREAMING_SNAKE_CASE_CONVENTION
Kabab Convention Styles
Kabab convention styles use a dash (-) to separate each word.
Kabab Case
Kabab case is written with all words in lowercase.
kebab-case-convention
Train Case
Train case or HTTP (Hypertext Transfer Protocol) header case is written with the same casing as Pascal case.
Train-Case-Convention
Cobol Case
Cobol case is written with all uppercase.
COBOL-CASE-CONVENTION
What About Acronyms?
Acronyms are treated just like any other word. The fact that acronyms are written in all uppercase is irrelevant. By writing it in all uppercase, you are breaking out of the casing convention standard and losing readability, especially when multiple acronyms are used. It can be difficult to know when one ends and another begins.
If you wanted to name a variable "from JSON to XML converter" some examples of how you would write it would be the following:
fromJsonToXmlConverter
from_json_to_xml_converter
From-Json-To-Xml-Converter
Single-character Words
There are valid use cases for single-character words, but they should be avoided as much as possible. Single-character words are more of a problem with Camel case and Pascal case, but regardless of the naming, they should still be avoided. If you have a name that has a single-character word, try to come up with another name that eliminates the single-character word. For example, if you had the following name:
containsABlankField
This could be renamed using one of the following names instead.
formIsPopulated
containsBlankFields
Conclusion
Casing convention styles are used to make names more readable when spaces cannot be used. Whatever language you are using, use the standard casing convention that language has set.