camelCase, snake_case, and kebab-case: Choosing a Naming Convention

Choose a case style that fits the language and destination, convert names consistently, and avoid subtle breakage in APIs, files, URLs, and databases.

By utilkit 4 min read Text
A close view of a backlit computer keyboard
Photo by Christian Wiediger on Unsplash

Case conventions turn spaces and capitalization into structure. They help people recognize a class, variable, file, database column, or URL before reading its documentation. The best convention is rarely a personal favorite; it is the established style of the language, framework, API, or system receiving the name.

Use the utilkit Case Converter to transform a list of labels into camel case, Pascal case, snake case, kebab case, title case, and other forms. Review the output when the source contains acronyms, numbers, punctuation, or already-compounded words, because automatic word-boundary detection cannot infer every intended meaning.

Know the common forms

  • camelCase begins lowercase and capitalizes later words.
  • PascalCase capitalizes every word and is common for types or classes.
  • snake_case joins lowercase words with underscores.
  • SCREAMING_SNAKE_CASE often identifies constants.
  • kebab-case joins lowercase words with hyphens and is common in URLs and CSS-oriented names.

These are tendencies, not universal laws. Python’s PEP 8, for example, documents conventions for functions, variables, classes, constants, and exceptions. Other ecosystems make different choices. Follow the local guide and nearby code before introducing a new pattern.

Respect the destination’s syntax

Hyphens work naturally in a URL path but are subtraction operators in many programming languages. Database identifiers may be case-folded or require quoting. File systems differ in case sensitivity, so files named only by capitalization can work on one machine and collide on another.

For a public API, consistency becomes a compatibility promise. Do not rename fields only to make a style guide tidier unless you can version the change. The Google JSON style guide illustrates one established convention, but the API you maintain may already have a different contract.

Decide how to handle edge cases

Write down how acronyms and initialisms behave: userId versus userID, or httpServer versus HTTPServer. Decide whether numbers create a new word boundary and how punctuation is removed. Stable rules prevent a converter from producing several spellings for the same concept.

Preserve domain terms even when a generic converter would split them incorrectly. Product names, chemical symbols, legal identifiers, and language-specific capitalization can need exceptions. A convention should improve recognition, not overwrite meaning.

Use one migration checklist

  1. Identify the destination’s existing naming rules.
  2. Convert a sample containing acronyms, numbers, and punctuation.
  3. Search for collisions after normalization.
  4. Update references, tests, documentation, and serialized contracts together.
  5. Provide compatibility aliases or a version transition when names are public.

Define acronyms, numbers, and boundaries

Most convention disputes appear at edges, not in simple two-word examples. Decide whether HTTPServer becomes httpServer or HTTPServer, whether version2 and version_2 mean the same thing, and how to treat punctuation, diacritics, and consecutive capitals. Include these cases in an executable fixture if a converter is part of a build or migration.

Distinguish display labels from identifiers. A user-facing label can preserve spaces and natural capitalization while an API key or filename follows a stricter form. Do not derive permanent database identifiers from labels if a later copy edit would break references. For public URLs, decide how redirects will preserve old slugs before changing the conversion rule.

During a migration, inventory consumers before renaming anything: source code, configuration, environment variables, serialized data, dashboards, documentation, and external integrations may all depend on the old spelling. Support both names briefly only with a clear removal date and observability for old usage. A consistent rename can still be a breaking change; safe conversion requires compatibility analysis and tests.

Naming consistency reduces friction because readers spend less time decoding form. Choose the convention that already communicates meaning in the destination, document the ambiguous edges, and use conversion tools for mechanical work—not for decisions about compatibility.