Naming convention guide
Camel Case Guide for Clean Code
camelCase is a naming style in which the first word starts with a lowercase letter and each later word starts with a capital letter, with no spaces or separators. For example, “user profile image” becomes “userProfileImage”.
The rules of camelCase
Start with a lowercase word, capitalise the first letter of every following word and remove spaces, hyphens and underscores. Preserve enough of the original meaning that another developer can understand the identifier without opening more files.
- Break the source phrase into individual words.
- Lowercase the first word.
- Capitalise the first letter of each remaining word.
- Join the words and remove separators.
Good camelCase examples
Clear identifiers describe the value or action rather than how the code happens to implement it.
| Use | Input | Result |
|---|---|---|
| Variable | current user name | currentUserName |
| Boolean | is account active | isAccountActive |
| Function | calculate order total | calculateOrderTotal |
| Event handler | handle form submit | handleFormSubmit |
| API property | created at timestamp | createdAtTimestamp |
camelCase versus PascalCase and snake_case
camelCase begins with a lowercase letter, PascalCase begins with a capital letter and snake_case separates lowercase words with underscores. JavaScript variables and functions commonly use camelCase, React components commonly use PascalCase, and Python code commonly uses snake_case.
Acronyms and numbers
Acronym handling varies by project. userId is often easier to read than userID, but an established codebase may use a different convention. Numbers can remain inside an identifier when they add meaning, such as addressLine2. Consistency with the surrounding code is more important than inventing a one-off rule.