Last updated
Naming Conventions in Programming
Different programming languages and frameworks have established conventions for naming variables, functions, classes, and files. Using the wrong convention in a codebase is a code smell — it signals unfamiliarity with the language or inconsistency in the team's style. This converter handles all the major conventions instantly.
The Main Naming Conventions
| Convention | Example | Used in |
|---|---|---|
| camelCase | getUserName | JavaScript variables & functions, Java methods |
| PascalCase | UserProfile | Classes in most languages, React components, C# methods |
| snake_case | user_name | Python variables & functions, Ruby, SQL columns, C |
| SCREAMING_SNAKE | MAX_RETRY_COUNT | Constants in Python, Java, C/C++ |
| kebab-case | user-profile | CSS classes, HTML attributes, URL slugs, Lisp |
| dot.case | user.profile | Config keys (Spring Boot, .NET), Lua |
Language-Specific Rules
- JavaScript/TypeScript:
camelCasefor variables and functions,PascalCasefor classes and React components,SCREAMING_SNAKEfor module-level constants. - Python:
snake_casefor everything except classes (PascalCase) and constants (SCREAMING_SNAKE). Enforced by PEP 8. - Java:
camelCasefor methods and variables,PascalCasefor classes,SCREAMING_SNAKEfor constants, package names in lowercase. - Go:
camelCasefor unexported identifiers,PascalCasefor exported (public) identifiers. No underscores in names. - CSS:
kebab-casefor class names and custom properties (--primary-color). - SQL:
snake_casefor table and column names is the most common convention.
Converting Between Cases in Code
// snake_case → camelCase
const toCamel = s => s.replace(/_([a-z])/g, (_, c) => c.toUpperCase());
toCamel('user_first_name'); // → "userFirstName"
// camelCase → snake_case
const toSnake = s => s.replace(/[A-Z]/g, c => '_' + c.toLowerCase());
toSnake('userFirstName'); // → "user_first_name"
// camelCase → kebab-case
const toKebab = s => s.replace(/[A-Z]/g, c => '-' + c.toLowerCase());
toKebab('userFirstName'); // → "user-first-name"
// Any → PascalCase
const toPascal = s => s
.replace(/[-_\s]+(.)/g, (_, c) => c.toUpperCase())
.replace(/^(.)/, c => c.toUpperCase());
toPascal('user_first_name'); // → "UserFirstName"
Most linters enforce naming conventions automatically. ESLint has a camelcase rule, Python's flake8 uses PEP 8 naming checks, and Go's golint flags non-idiomatic names. Setting these up in your CI pipeline prevents naming inconsistencies from ever reaching the codebase.