Fotolia
A guide to common variable naming conventions
Every developer should know the basic variable naming conventions to more easily move from language to language. Review the common ones here like Pascal, camel and snake case.
It has been said that there are only two difficult tasks in modern software development: distributed cache invalidation and how to name stuff. The following variable naming conventions won't assist with your distributed cache, but they will help you standardize how the format of your code communicates programming concepts to fellow developers.
Variable naming conventions
The standard naming conventions used in modern software development are as follows:
- Pascal case
- camel case
- snake case
- kebab case
Pascal case
Popularized by the Turbo Pascal programming language, Pascal case requires the first letter of a variable be uppercase, along with the first letter of every new word compounded together to create the variable. Here are two examples of Pascal case:
- ThisIsPascalCase
- AnotherPascalCaseExample
Camel case
Camel case follows the same rules as Pascal case but drops the requirement to capitalize the first letter. To differentiate between cases where the first letter is or is not capitalized, software developers often use the terms "upper camel case" and "lower camel case."
Upper camel case looks the same as Pascal case. Lower camel case is also known as "dromedary case," as a dromedary camel has one less hump than the two-humped Bactrian camel.
The following are examples of camel case:
- thisIsDromedaryCamelCase
- ThisIsUpperCamelCase
Snake and kebab case
For those who appreciate more whitespace between concatenated words, there is snake case and kebab case. Snake case separates words with underscores; it's also called pothole case. When every letter is capitalized, it is known as screaming snake case:
- this_is_snake_case
- THIS_IS_SCREAMING_SNAKE_CASE
Kebab case follows the same rules as snake case, just with a dash instead of an underscore. When all capital letters are used, it's known as a scream kebab.
- this-is-kebab-case
- THIS-IS-A-SCREAM-KEBAB
One of the problems with kebab case is that the dash can be confused with a minus sign, which can create difficult-to-troubleshoot bugs in code.
Variable naming convention best practices
Which of the various variable naming conventions should you use? It all depends on the programming language.
For example, Java demands classes to be in Pascal case, variables in dromedary case and constants in screaming snake case. Java does not use kebab case in any standardized manner, while Jekyll uses dashes in URLs to define the day, month and year an article was posted.
Whenever you develop code in a new language, get comfortable with the variable naming conventions and always check with your DevOps team if your organization ever deviates from the standard. It will make your code more readable and help your code blend with all of the code commits, pulls and merges.