CAMELCASE VS SNAKE_CASE VS KEBAB-CASE: WHEN TO USE EACH
Naming conventions are one of those topics that seem trivial until you're maintaining a codebase where four different conventions exist in the same file. Understanding when and why each style is used â and which languages enforce which â prevents confusion when moving between technologies.
THE NAMING CONVENTION STYLES
camelCase
First word lowercase, subsequent words capitalized. No separators. Example: getUserName, isActive, totalScore. Named after the humps formed by the capital letters.
PascalCase
Every word capitalized, including the first. No separators. Example: UserProfile, GameBoard, HttpRequest. Also called UpperCamelCase. Used almost universally for class and type names.
snake_case
All lowercase, words separated by underscores. Example: user_name, is_active, total_score. Common in Python, Ruby, and SQL.
kebab-case
All lowercase, words separated by hyphens. Example: user-name, is-active, background-color. Named after letters skewered on a kebab. Used in CSS, HTML attributes, and URLs. Not valid in most programming languages because - is a subtraction operator.
SCREAMING_SNAKE_CASE
All uppercase with underscores. Example: MAX_SCORE, DEFAULT_TIMEOUT, API_KEY. Used almost exclusively for constants â values that should never change after being set.
WHICH LANGUAGES USE WHICH
| LANGUAGE | VARIABLES / FUNCTIONS | CLASSES | CONSTANTS |
|---|---|---|---|
| JavaScript / TypeScript | camelCase | PascalCase | SCREAMING_SNAKE |
| Python | snake_case | PascalCase | SCREAMING_SNAKE |
| Java | camelCase | PascalCase | SCREAMING_SNAKE |
| C# | camelCase (private), PascalCase (public) | PascalCase | PascalCase |
| Go | camelCase | PascalCase | camelCase or PascalCase |
| Ruby | snake_case | PascalCase | SCREAMING_SNAKE |
| Rust | snake_case | PascalCase | SCREAMING_SNAKE |
| CSS | kebab-case | N/A | --kebab-case (custom props) |
| SQL | snake_case | N/A | UPPERCASE |
WHY DIFFERENT CONVENTIONS EXIST
The differences aren't arbitrary â they reflect the languages' origins and communities. Python's snake_case convention is partly a readability choice (the PEP 8 style guide formalized it) and partly a reaction to C-era programming where variable names were often one or two characters and case didn't matter.
JavaScript inherited camelCase from Java. Brendan Eich created JavaScript in ten days while modeling it partly on Java syntax, and the camelCase convention came along with the Java-style syntax. DOM APIs like getElementById and addEventListener cemented camelCase as the JavaScript norm.
CSS uses kebab-case because hyphens don't conflict with CSS syntax â property names like background-color and font-family use hyphens as separators. In CSS, underscores historically had different browser behavior, and camelCase isn't lowercase (CSS properties are case-insensitive but conventionally lowercase).
THE CROSS-LANGUAGE CONVERSION PROBLEM
The real pain of naming conventions emerges when you're working across multiple languages or layers of a stack. A full-stack developer might have:
- A Python backend with
user_nameandcreated_at - A JSON API that should return
userNameandcreatedAt(camelCase, JavaScript convention) - A database with columns
user_nameandcreated_at(SQL snake_case) - CSS classes like
.user-profileand.created-date(kebab-case)
Every layer uses a different convention for the same concept. Most frameworks handle this automatically â Django REST Framework can serialize snake_case Python to camelCase JSON, and CSS preprocessors can help manage class names. But when they don't, manual conversion is tedious and error-prone.
WHEN TO DEVIATE FROM CONVENTION
The short answer: almost never, at least within a single language context. Consistency with your language's conventions makes code predictable for anyone else who reads it â or for future-you returning to the codebase six months later.
The case for deviation is specific: if you're matching an external API or data format exactly, use the format the external system expects. If your company has an established style guide that differs from community convention, follow the style guide for internal code.
Within a language, mixing conventions is a strong signal that code was written by multiple people without coordination, or that it evolved without refactoring. It's worth the cleanup effort.
Need to convert between naming conventions instantly? The PixelArcade Case Converter handles camelCase, PascalCase, snake_case, and kebab-case conversions with one click â no installation, runs in your browser.