camelCase vs snake_case: When to Use Which
camelCase and snake_case are the two most common naming conventions in programming. Choosing the right one depends on the language, framework, and context you are working in.
What Is camelCase?
camelCase joins words together with no separator, capitalizing the first letter of each word except the first: myVariableName, getUserById, totalItemCount.
The name comes from the uppercase letters in the middle of the word, resembling the humps of a camel.
What Is snake_case?
snake_case separates words with underscores and uses all lowercase letters: my_variable_name, get_user_by_id, total_item_count.
Side-by-Side Comparison
| Feature | camelCase | snake_case |
|---|---|---|
| Separator | None (uppercase letter) | Underscore (_) |
| First letter | Lowercase | Lowercase |
| Readability | Good for short names | Excellent for long names |
| Typing speed | Faster (no underscore) | Slower (underscore key) |
| Length | Shorter | Longer |
Which Languages Use Which?
| Convention | Languages / Frameworks |
|---|---|
| camelCase | JavaScript, TypeScript, Java, Swift, Kotlin, Dart, JSON |
| snake_case | Python, Ruby, Rust, Elixir, PHP (partially), SQL, C (partially) |
When to Use camelCase
- JavaScript or TypeScript variables and functions
- Java method and variable names
- JSON object keys in frontend-centric APIs
- Swift and Kotlin identifiers
- React state variables and event handlers
When to Use snake_case
- Python variables and functions (PEP 8 mandates this)
- Ruby method and variable names
- Database table and column names
- REST API fields for Python/Ruby backends
- Configuration file keys
- Environment variable names (in UPPER_SNAKE_CASE)
Converting Between Them
Converting camelCase to snake_case: insert an underscore before each uppercase letter, then lowercase everything. getUserById becomes get_user_by_id.
Converting snake_case to camelCase: remove each underscore and capitalize the following letter. get_user_by_id becomes getUserById.
Use our camelCase converter or snake_case converter to do this instantly, or try the case converter hub to see all formats at once.
The Mixed-Codebase Problem
The most common situation where developers encounter both conventions is at the boundary between a Python/Ruby backend (snake_case) and a JavaScript frontend (camelCase). The typical solution is to convert API response keys at the boundary using a middleware or utility function.
Summary
There is no universally "better" convention. Follow the standard of whatever language or framework you are using. Consistency within a project matters far more than which convention you choose.