Skip to content
DocsAll
教程

Case Conversion Rules: CamelCase, Underscore, and Naming Conventions

DocsAll 团队 · Published on April 7, 2026 · Updated on July 12, 2026
Letter CaseNaming ConventionsProgramming

Why Naming Conventions Matter

How to write variable names, function names, and class names in code isn't just personal preference. Unified naming conventions make code readable, team collaboration smooth, and style consistent. Different languages have different conventions; mixing them up looks unprofessional.

Common Naming Conventions

camelCase

First word lowercase, subsequent words capitalized:

firstName
lastName
getUserInfo
isLoggedIn

Used for: JavaScript/TypeScript variables and functions, Java methods and variables, C# methods and variables.

PascalCase (UpperCamelCase)

Every word capitalized:

FirstName
UserService
HomeController

Used for: JavaScript/TypeScript classes and interfaces, Java classes, C# classes and methods, React components.

snake_case

All lowercase, words separated by underscores:

first_name
last_name
get_user_info

Used for: Python variables and functions, Ruby variables and methods, database field names, PHP variables.

UPPER_SNAKE_CASE (SCREAMING_SNAKE_CASE)

All uppercase, separated by underscores:

MAX_RETRY
DEFAULT_TIMEOUT
API_BASE_URL

Used for: Constants, config options, enum values. Almost all languages use this convention for naming constants.

kebab-case

All lowercase, separated by hyphens:

first-name
user-profile
api-key

Used for: URL paths, HTML/CSS class names, file names, config file keys.

dot.case

Separated by dots:

user.name
config.timeout

Used for: Config file hierarchical keys, namespaces.

Language Convention Quick Reference

JavaScript / TypeScript

  • Variables, functions: camelCase (getUserInfo)
  • Classes, interfaces, types: PascalCase (UserService)
  • Constants: UPPER_SNAKE_CASE (MAX_RETRY)
  • Private members: underscore-prefixed camelCase (_privateVar)

Python

  • Variables, functions: snake_case (get_user_info)
  • Classes: PascalCase (UserService)
  • Constants: UPPER_SNAKE_CASE (MAX_RETRY)
  • Private members: underscore-prefixed snake_case (_private_var)

Java

  • Variables, methods: camelCase (getUserInfo)
  • Classes: PascalCase (UserService)
  • Constants: UPPER_SNAKE_CASE (MAX_RETRY)
  • Package names: all lowercase (com.example.service)

CSS / HTML

  • Class names: kebab-case (user-profile)
  • IDs: kebab-case or camelCase (team's choice)

Database

  • Table names, field names: snake_case (user_name)
  • Some use camelCase; depends on team conventions

URL

  • Paths: kebab-case (/user-profile/settings)
  • Query parameters: camelCase or snake_case (?userId=123 or ?user_id=123)

Conversion Rules

camelCase → snake_case

  1. Find uppercase letters
  2. Add an underscore before the uppercase letter
  3. Convert all to lowercase

Example: getUserInfo → get_user_info

snake_case → camelCase

  1. Find underscores
  2. Capitalize the letter after the underscore
  3. Remove the underscore

Example: get_user_info → getUserInfo

PascalCase → camelCase

Lowercase the first letter, keep the rest unchanged.

Example: UserService → userService

camelCase → PascalCase

Capitalize the first letter, keep the rest unchanged.

Example: userService → UserService

kebab-case → camelCase

  1. Find hyphens
  2. Capitalize the letter after the hyphen
  3. Remove the hyphen

Example: user-profile → userProfile

Common Mistakes

Mixing Conventions

Mixing camelCase and snake_case in the same project looks messy. Pick one convention and stick with it.

Abbreviation Handling

Should abbreviations be all uppercase?

  • URL or Url? userId or userID?
  • Convention: Two-letter abbreviations all uppercase (ID, URL), three letters and above capitalize the first letter (Http, Xml)
  • Just be consistent across the team; the key is consistency throughout the project

Initialisms

How to write HTTP, XML, URL in camelCase?

  • Recommended: httpUrl, xmlParser (treat as regular words)
  • Some prefer: HTTPUrl, XMLParser (keep abbreviations uppercase)
  • Be consistent across the team

Number Handling

user2name or user2Name?

  • camelCase: user2Name (capitalize the first letter of the word after the number)
  • snake_case: user2_name

Converting Case with DocsAll

The Case Conversion Tool supports:

  • All uppercase / all lowercase
  • Capitalize first letter
  • Convert between camelCase / PascalCase / snake_case / kebab-case
  • Capitalize first letter of sentences

Operation:

  1. Paste text
  2. Select conversion type
  3. Copy the result

Browser-side conversion, text is not uploaded.

Summary

The key to naming conventions: variables and functions use camelCase or snake_case (depending on language), classes use PascalCase, constants use UPPER_SNAKE_CASE, URLs use kebab-case. Team consistency is most important. The DocsAll Case Conversion Tool runs in the browser, and data is not sent out.

D
DocsAll 团队 DocsAll 编辑团队

DocsAll 编辑团队,由产品经理、工程师和内容编辑组成,致力于分享实用的办公文档处理技巧。