Naming things is hard, especially if there are multiple words that make up that name. Remembering names of naming conventions can also be hard. However, regardless of their names, these conventions can help make your code readable. Here is a guide to commonly named cases used in variable names in coding:
- Capitalization-based Casing
- Delimited-based Casing
- The Importance of Casing
Camel casing and Pascal casing involve words that are smashed together, without delimiters. Their casing is within the words themselves.
camelCased - Camel Casing
When it comes to camel casing, think of humps on a camel. A camel’s hump follows the shape of a bell. A camel cam have multiple humps. When doing camel-cased names, the first letter is lower-cased. Each subsequent word in the variable name starts with a capital letter. Consider some of these camel-cased names:
PascalCased - Pascal Casing
Pascal casing is similar to camel casing, except the first word also starts with a capital letter. This kind of casing was popular in programs written in the Pascal programming language, hence the name. Consider some of these Pascal-cased names:
Kebab casing and snake casing deal with delimiters. Rather than the words smashed together, the words in the variable name are delimited with characters. They may also have some capitalization variations.
kebab-cased - Kebab Casing
Kebab casing puts an ASCII skewer through the words of a variable name, separating each word with dashes. Consider some of these kebab-cased names:
Camel kebab casing is as the name suggests - the first letter of the first word is not capitalized. However, subsequent words as part of the name are capitalized. These are examples of camel-kebab-cased names:
Pascal kebab casing is when the first letter of each word on the kebab is capitalized. These are examples of Pascal-kebab-cased variable names:
Upper kebab casing - also known as screaming kebab case, COBOL case, and train case - is kebab-cased with all upper-case characters. These are examples of variables that follow this convention:
snake_cased - Snake Casing
Snake casing is similar to kebab casing, except it uses underscores instead of dashes. Consider some of these snake-cased names:
There is a subset of snake casing called screaming snake casing or upper case snake casing. That involves the underscore character with all capital letters. These are screaming snake case examples:
Snake casing also can have camel and Pascal variations. These are camel-snake-cased variables:
These are Pascal-snake-cased variables:
Note: There are debates on capitalizing words like “of” and “the”. Whatever you choose, be consistent about it in your code base. Consistency is another key factor for readability.
The Importance of Casing
While these names may seem trivial, what do they look like without these casing conventions? What if they were in flatcase - all lower-cased characters, all words mashed together?
If you have context around those variable names, you might be able to infer what they are at a quick glance. However, not everyone has that ability. Some folks may also rely on assistive technologies such as screen readers. Do you know how your variables’ names sound?
I was testing this out with Microsoft Narrator in Windows 11, and this is what I get:
dateofbirth- “day toff birth”
dateOfBirth- “date of birth”
date-of-birth- “date of birth”
date_of_birth- “date of underscore of underscore birth”
DateOfBirth- “date of birth”
So the casing choices matter - they can help the readability of the code in many forms.
I hope this helps you remember the names of these cases.
If you find yourself working with devs who need more guidance on how to write better code, consider signing up for our mentoring opportunities.