Names in code, file names and web addresses cannot contain spaces. Over time, several conventions have grown up for joining words together. They are all readable, but each community has its own favourite, and mixing them causes bugs and untidy projects.
The main styles
| Style | Example | Common use |
|---|---|---|
| camelCase | userAccountId | Variables and functions in JavaScript, Java, Swift |
| PascalCase | UserAccountId | Classes and components in many languages |
| snake_case | user_account_id | Python, Ruby, database columns, Rust functions |
| kebab-case | user-account-id | URLs, CSS class names, file names |
| CONSTANT_CASE | USER_ACCOUNT_ID | Constants and environment variables |
| dot.case | user.account.id | Config keys, package names |
Why conventions matter
A consistent style makes names predictable. If every function in a project is camelCase, you can guess the name of the next one. It also avoids errors, since many systems are case-sensitive: userId and userid are different names to a program, and file names on a Linux server are case-sensitive while those on Windows are not.
Which should I use for web addresses?
Use lower-case kebab-case in URLs. Google's guidance recommends hyphens to separate words in a URL, because it treats a hyphen as a word separator, while an underscore is generally not read as one. So /blog/strong-password-tips is a better address than /blog/strong_password_tips. Lower case also avoids duplicate pages when a server treats upper and lower case differently.
Title case and sentence case
For headings written for people, there are two common styles. Title case capitalises the main words, and sentence case capitalises only the first word and proper names. Rules for title case differ between style guides: for example, some capitalise every word of four letters or more, and others leave short words such as "of", "and" and "the" in lower case. If your publisher has a style guide, follow it, and treat an automatic converter as a first draft.
Pitfalls when converting
- Acronyms. Is it
userIDoruserId? Pick one rule, such as treating acronyms as ordinary words, and stick to it. - Names and proper nouns. An automatic converter cannot know that "NASA" or "McDonald" has a special form.
- Numbers.
address2andaddress_2may be handled differently. - Non-English letters. Accented letters are kept by modern tools, but not every programming language allows them in names.
Try it
Paste your text and click a style. Programming styles split joined words first, so userID becomes user_id. Use "Use result as input" to chain conversions. To count what you have written, try the Word Counter.