Sergey Nivens - Fotolia
Camel case and snake case stand at opposite ends of the variable naming convention spectrum.
When multiple words are used to form a variable, camel case joins those words together, without any white space, and delineates the start of each new word with a capital letter.
In contrast, snake case uses an underscore between words to create separation. Variable names cannot contain spaces, which reduces readability when multiple words must be used to describe a variable's purpose. The underscore in a snake-cased variable tries to minimize this shortcoming.
Snake case examples
The following variable names follow the snake case naming convention:
Some languages, like Java, use snake case with all uppercase letters to indicate a variable is a constant. For example, INTEREST_RATE would be a Java constant. When all of the snake-cased letters are uppercase, this is known as screaming snake case.
Camel case examples
The following are examples of variables that use the camel case naming convention:
When the first letter of a camel-cased variable is uppercase, it is also known as Pascal case or upper camel case. When it is not, it is often referred to as lower camel case.
Snake case vs. camel case usage
While individual languages specify their own naming conventions, there is little consistency across languages regarding camel case versus snake case usage.
Languages such as Java and Kotlin, which have a C and C++ heritage, use lower camel case for variables and methods, and upper camel case for reference types such as enums, classes and interfaces. Screaming snake case is used for variables.
Scripting languages, as demonstrated in the Python style guide, recommend snake case in the instances where C-based languages use camel case.
Variable naming conventions, such as snake case or camel case, are standardized differently for each programming language. Furthermore, independent software development teams often break these rules when corner cases are encountered.
When you learn a new software development language, or join a new development team, always be sure to appraise yourself of the variable naming conventions used to ensure that all your co-developers are speaking the same language.
Dig Deeper on Software programming languages
Related Q&A from Cameron McKenzie
Both Git fork and clone create copies of a repository, but they offer drastically different levels of access, isolation and control over the target ... Continue Reading
What is the difference between a variable written in kebab case vs. camel case? Here we'll show you how these naming conventions differ and when to ... Continue Reading
Sun Microsystems architects designed Java to be cross-platform. But why? Here we look at not only why Java works across platforms, but also how it ... Continue Reading