Programming Naming Conventions Explained: camelCase, snake_case, and More
Every programming language lets you name variables and functions however you want, but each has a dominant convention that most codebases follow. Mixing conventions within one project doesn't break anything technically, but it makes code noticeably harder to read and signals inconsistency to anyone reviewing it — which is why most style guides enforce one convention strictly.
The main conventions
camelCase: first word lowercase, each subsequent word capitalized, no separators — userAccountBalance. The default for variables and functions in JavaScript, Java, and Swift.
PascalCase: every word capitalized, no separators — UserAccountBalance. Used for class and component names in most languages, including JavaScript and Java, even when the rest of the codebase uses camelCase for variables.
snake_case: all lowercase, words separated by underscores — user_account_balance. The standard for variables and functions in Python and Ruby, and for database column names almost everywhere regardless of the application language.
kebab-case: all lowercase, words separated by hyphens — user-account-balance. Not valid as a variable name in most programming languages (the hyphen is read as subtraction), but standard for URLs, CSS class names, and file names.
UPPER_SNAKE_CASE: all uppercase with underscores — MAX_RETRY_COUNT. Reserved almost universally for constants — values that don't change during program execution.
Why the convention differs by context, not just by language
It's common for a single file to correctly use several conventions at once: a Python file might use snake_case for its own functions, PascalCase for a class it defines, and UPPER_SNAKE_CASE for a constant at the top of the file. This isn't inconsistency — each convention is signaling something different about what kind of thing the name refers to, and experienced developers read those signals automatically.
Where this trips people up
The most common naming-convention bug isn't stylistic — it's converting a name between conventions without updating every reference to it. Renaming a JSON field from user_id to userId to match a JavaScript convention, without updating the API on the other end, breaks the connection between the two systems entirely, since user_id and userId are treated as completely different keys. When converting naming conventions across a codebase, always do a full search for every usage of the old name first.
Try it yourself
Our Case Converter converts text between UPPERCASE, lowercase, Title Case, Sentence case, camelCase, PascalCase, snake_case, and kebab-case instantly, which is useful for renaming variables consistently or converting a heading into a URL slug.
This guide is for general understanding. Always check your project's specific style guide, since some teams deviate from language defaults.
Frequently asked questions
Why does JavaScript use camelCase but Python uses snake_case?
These are historical conventions set by each language's original style guides and standard libraries, which the wider community then adopted for consistency — there's no technical reason one is required over the other.
Can I mix naming conventions in one file?
Yes, and it's normal — different conventions typically signal different kinds of names (classes vs. variables vs. constants) within the same file, following the dominant style guide for that language.
Why can't I use kebab-case for a variable name?
Because most programming languages interpret the hyphen as a subtraction operator, so user-name would be read as "user minus name" rather than a single identifier.