Naming Conventions in Programming: The Complete Guide
Naming conventions are systematic rules for choosing identifiers in source code. Using the right convention improves readability, reduces bugs, and makes codebases easier to maintain across teams.
Why Naming Conventions Matter
Code is read far more often than it is written. Consistent naming lets developers understand the purpose and scope of a variable, function, or class at a glance. Most languages have official style guides that mandate specific conventions, and violating them makes your code feel foreign to other developers.
The Major Naming Conventions
camelCase
Words are joined with no separator; every word after the first is capitalized: getUserName, totalPrice. This is the default for variables and functions in JavaScript, TypeScript, Java, and Swift.
PascalCase (UpperCamelCase)
Like camelCase, but the first word is also capitalized: UserAccount, HttpClient. Used for class names in nearly every language, React components, and TypeScript interfaces.
snake_case
Words are separated by underscores, all lowercase: user_name, get_total_price. Mandated by PEP 8 for Python, also standard in Ruby, Rust, and SQL.
SCREAMING_SNAKE_CASE
All uppercase with underscores: MAX_RETRY_COUNT, API_BASE_URL. Used for constants in most languages and environment variables.
kebab-case
Words separated by hyphens, all lowercase: my-component, user-profile. Standard for CSS classes, HTML attributes, URL slugs, and CLI flags.
dot.case
Words separated by dots: com.example.app. Used in Java package names, property file keys, and some configuration formats.
Convention by Language
| Language | Variables/Functions | Classes | Constants |
|---|---|---|---|
| JavaScript / TypeScript | camelCase | PascalCase | SCREAMING_SNAKE |
| Python | snake_case | PascalCase | SCREAMING_SNAKE |
| Java | camelCase | PascalCase | SCREAMING_SNAKE |
| Ruby | snake_case | PascalCase | SCREAMING_SNAKE |
| Rust | snake_case | PascalCase | SCREAMING_SNAKE |
| Go | camelCase | PascalCase | camelCase / PascalCase |
| C# | camelCase | PascalCase | PascalCase |
| Swift | camelCase | PascalCase | camelCase |
| PHP | camelCase / snake_case | PascalCase | SCREAMING_SNAKE |
| CSS | kebab-case | — | — |
Best Practices
- Follow your language's style guide. PEP 8 for Python, Google Style for Java, Airbnb for JavaScript — don't invent your own rules.
- Be consistent within a project. Mixing camelCase and snake_case in the same file confuses everyone.
- Use descriptive names.
getUserByIdbeatsgetU. The convention is the format; the content should be meaningful. - Avoid abbreviations.
calculateTotalPriceis better thancalcTotPrc. - Match the ecosystem. If your React project uses camelCase props but your Python API returns snake_case, convert at the boundary.
Converting Between Conventions
Need to switch formats? Use our camelCase converter, snake_case converter, PascalCase converter, or kebab-case converter. Or try the case converter hub to compare all formats side by side.
Conclusion
Naming conventions are not arbitrary. They encode information about scope, type, and intent. Learn the standard for your language, apply it consistently, and your code will be easier to read, review, and maintain.