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

StyleExample
camelCasegetUserByEmail
PascalCaseUserAccount
snake_caseget_user_by_email
SCREAMING_SNAKEMAX_RETRY_COUNT
kebab-caseuser-account
dot.caseuser.account.email

Convert any string between all of them at once with the case converter.

Per-language conventions

JavaScript / TypeScript

  • Variables, functions, methods, object keyscamelCase.
  • Classes, React components, TS types/interfaces, enumsPascalCase.
  • Constants (module-level, truly immutable)SCREAMING_SNAKE_CASE. In practice most modern JS just uses camelCase for these too.
  • File nameskebab-case.ts (Node ecosystem) or PascalCase.tsx (React components).

Python

  • Variables, functions, methods, modulessnake_case.
  • ClassesPascalCase.
  • ConstantsSCREAMING_SNAKE_CASE.
  • PEP 8 is the reference; every linter checks it.

Go

  • Exported (public) identifiersPascalCase.
  • Unexported (private) identifierscamelCase.
  • The case is the visibility modifier. There's no public/private keyword.
  • Acronyms stay all-caps: URL, HTTP, ID — not Url.

Rust

  • Variables, functions, modules, fieldssnake_case.
  • Types, traits, enumsPascalCase.
  • Constants and staticsSCREAMING_SNAKE_CASE.
  • cargo clippy will yell if you break the rules.

Ruby

  • Variables, methodssnake_case.
  • Classes, modulesPascalCase.
  • ConstantsSCREAMING_SNAKE_CASE (any identifier starting with a capital is a constant).

Java / Kotlin / C# / Swift

  • Classes, typesPascalCase.
  • Methods, variablescamelCase.
  • Constants — Java/Kotlin use SCREAMING_SNAKE_CASE; C# uses PascalCase; Swift uses camelCase.

SQL

  • Table and column namessnake_case, lowercase. Pluralize table names or not, but be consistent.
  • SQL keywordsUPPER CASE by 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

  1. Follow the language convention. Don't invent your own.
  2. Acronyms — pick a rule and enforce it: UserID vs UserId. Both are defensible; inconsistency isn't.
  3. Boolean names start with is, has, can, or should.
  4. Never abbreviate unless the abbreviation is universally understood (URL, ID). usr, cfg, mgr — spell it out.
  5. Length is not the enemy. getUserByEmailAddress beats gubea.

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.

Try the tools

Related reading