Case conventions
Per-language naming conventions for JS, Python, Go, Rust, Ruby, Java, SQL — plus the rules for URLs, env vars, CSS classes, and API payloads.
•5 min read
Naming is famously hard; picking the case shouldn't be. Every language has a convention, most environments have one too, and following them costs nothing while making your code feel native. Here's the practical guide — one page, no arguments.
The cases you'll actually use
| Style | Example |
|---|---|
| camelCase | getUserByEmail |
| PascalCase | UserAccount |
| snake_case | get_user_by_email |
| SCREAMING_SNAKE | MAX_RETRY_COUNT |
| kebab-case | user-account |
| dot.case | user.account.email |
Convert any string between all of them at once with the case converter.
Per-language conventions
JavaScript / TypeScript
- Variables, functions, methods, object keys —
camelCase. - Classes, React components, TS types/interfaces, enums —
PascalCase. - Constants (module-level, truly immutable) —
SCREAMING_SNAKE_CASE. In practice most modern JS just uses camelCase for these too. - File names —
kebab-case.ts(Node ecosystem) orPascalCase.tsx(React components).
Python
- Variables, functions, methods, modules —
snake_case. - Classes —
PascalCase. - Constants —
SCREAMING_SNAKE_CASE. - PEP 8 is the reference; every linter checks it.
Go
- Exported (public) identifiers —
PascalCase. - Unexported (private) identifiers —
camelCase. - The case is the visibility modifier. There's no
public/privatekeyword. - Acronyms stay all-caps:
URL,HTTP,ID— notUrl.
Rust
- Variables, functions, modules, fields —
snake_case. - Types, traits, enums —
PascalCase. - Constants and statics —
SCREAMING_SNAKE_CASE. cargo clippywill yell if you break the rules.
Ruby
- Variables, methods —
snake_case. - Classes, modules —
PascalCase. - Constants —
SCREAMING_SNAKE_CASE(any identifier starting with a capital is a constant).
Java / Kotlin / C# / Swift
- Classes, types —
PascalCase. - Methods, variables —
camelCase. - Constants — Java/Kotlin use
SCREAMING_SNAKE_CASE; C# usesPascalCase; Swift usescamelCase.
SQL
- Table and column names —
snake_case, lowercase. Pluralize table names or not, but be consistent. - SQL keywords —
UPPER CASEby tradition (not required, purely for readability). - Avoid case-sensitive identifiers (quoted names). It's a rabbit hole.
Non-code contexts
URL paths and slugs
- kebab-case. Hyphens separate words; Google treats them as separators, underscores as joiners.
- Lowercase everything. Case-sensitive URLs are a support ticket generator.
- Use our slugify tool to convert arbitrary text.
Environment variables
SCREAMING_SNAKE_CASE. Universal convention across every OS and language.- Prefix with the app name to avoid collisions:
MYAPP_DATABASE_URL. - Keep names alphanumeric + underscore. Some shells reject other characters.
CSS classes and HTML attributes
kebab-case. It's the CSS convention and matches the HTML attribute style.- BEM adds structure:
block__element--modifier. Optional but useful in large codebases.
File names
- Default to
kebab-case. Works on every filesystem, no case-sensitivity gotchas between macOS and Linux. - React components are the common exception:
UserCard.tsx.
API JSON payloads
- camelCase is dominant in JS-centric ecosystems.
- snake_case is common in Python/Ruby/Rust backends.
- Pick one per API and stick with it. Mixing styles across endpoints is the actual sin.
Cross-team style rules that pay off
- Follow the language convention. Don't invent your own.
- Acronyms — pick a rule and enforce it:
UserIDvsUserId. Both are defensible; inconsistency isn't. - Boolean names start with
is,has,can, orshould. - Never abbreviate unless the abbreviation is universally understood (
URL,ID).usr,cfg,mgr— spell it out. - Length is not the enemy.
getUserByEmailAddressbeatsgubea.
The whole point of a convention is that no one has to think about it. Pick the one your language uses, enforce it with a linter, and spend your naming energy on what the identifier represents.