camelCase vs snake_case: When to Use Which

5 min read

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

FeaturecamelCasesnake_case
SeparatorNone (uppercase letter)Underscore (_)
First letterLowercaseLowercase
ReadabilityGood for short namesExcellent for long names
Typing speedFaster (no underscore)Slower (underscore key)
LengthShorterLonger

Which Languages Use Which?

ConventionLanguages / Frameworks
camelCaseJavaScript, TypeScript, Java, Swift, Kotlin, Dart, JSON
snake_casePython, 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.