Why is it called a camel case
Have you ever seen a word or phrase in programming or design where the first word is lowercase, and every subsequent word starts with a capital letter, like myVariableName or calculateTotalAmount? This common convention has a rather descriptive name: camel case. But why on earth do we call it that? The answer, like many things in computing, is rooted in its visual appearance.
The Visual Analogy: Humps and the Camel
The most straightforward explanation for the term "camel case" lies in its visual resemblance to the humps of a camel. Imagine a camel walking across a desert landscape. The lowercase letters form the flatter parts of the terrain, while the uppercase letters, standing taller and more prominent, are like the distinctive humps.
When you have a string of words joined together without spaces, and each new word begins with a capital letter, it creates a series of these "humps" within the text. For instance:
firstName- Here, the 'N' in "Name" creates the first hump.userLoginCount- The 'L' in "Login" and the 'C' in "Count" form two humps.internationalization- This is a classic example where the uppercase letters effectively create multiple humps.
This visual analogy is quite strong and immediately understandable, making "camel case" a memorable and intuitive name for this particular naming convention.
Variations of Camel Case
It's important to note that "camel case" often refers to a specific type of casing, but there are related conventions that are sometimes grouped under the broader umbrella or have their own distinct names:
- Lower Camel Case (or just Camel Case): This is the most common interpretation. The very first letter of the entire identifier is lowercase, and subsequent words start with an uppercase letter. Examples:
myVariable,getUserInfo. - Upper Camel Case (or Pascal Case): In this variation, *every* word, including the very first one, starts with an uppercase letter. Examples:
MyClassName,CalculateTotalAmount. While visually similar (still having "humps"), the starting uppercase letter differentiates it. Often, programmers will specifically call this "Pascal Case" to avoid confusion.
The term "camel case" is most frequently associated with the lower camel case format, precisely because the initial lowercase letter creates a dip before the first "hump."
Where Did It Come From?
While it's difficult to pinpoint the exact inventor of the term "camel case," its usage became widespread with the rise of programming languages. Early programming languages like C, C++, and Java often used conventions that favored this type of naming for variables, functions, and other identifiers. Developers needed a consistent and readable way to name things, especially when they involved multiple words. The "camel case" metaphor provided an easy way to describe and remember the pattern.
The popularity of languages that embrace camel case (like JavaScript, Python for certain contexts, and many others) has cemented its place in the developer lexicon. It helps in:
- Readability: Breaking up compound words with capitals makes them easier to scan and understand, especially in long code.
- Distinguishing Words: Without spaces, it can be hard to tell where one word ends and another begins. The capital letters act as clear delimiters.
- Avoiding Reserved Words: In many programming languages, spaces are not allowed in identifiers. Camel case provides a way to create meaningful names without using spaces.
In Summary
So, the next time you encounter a variable named productPrice or a function called processUserData, you'll know that the name "camel case" comes from the visual appearance of the uppercase letters acting like the humps on a camel's back, making multi-word identifiers easier to read and manage.
Frequently Asked Questions
How does camel case improve code readability?
Camel case improves readability by using capital letters to clearly delineate the start of each new word within a compound identifier. This makes it easier for programmers to scan and understand the meaning of variable names, function names, and other code elements at a glance, especially when dealing with longer or more complex names.
Why is it not called "hump case"?
While "hump case" might seem like a more literal description, "camel case" likely gained popularity due to its memorable and slightly whimsical nature. The camel is a widely recognized animal with prominent humps, making the analogy strong and easily recalled. The term likely stuck because it was more evocative and easily adopted by the programming community.
Is camel case the only way to name variables?
No, camel case is just one of several popular naming conventions. Other common styles include snake_case (where words are separated by underscores, like my_variable), kebab-case (words separated by hyphens, often used in web development for CSS classes and HTML attributes, like my-class), and PascalCase (also known as upper camel case, where the first letter is also capitalized, like MyClass).
What's the difference between camel case and Pascal case?
The primary difference lies in the capitalization of the very first letter. In camel case (or lower camel case), the first letter of the entire identifier is lowercase (e.g., userProfile). In Pascal case (or upper camel case), the first letter of the entire identifier is capitalized (e.g., UserProfile). Both use capitalization to separate words.

