Clarity and Descriptiveness:
Names should clearly describe the purpose or role of the variable, function, or class. Avoid vague or overly generic names like data
, temp
, or foo
.
Consistency:
Follow a consistent naming pattern across the entire codebase. Consistency aids readability and makes the code easier to navigate.
Avoid Abbreviations:
Avoid using abbreviations or acronyms unless they are widely understood within the team or industry.
Meaningful Names:
Names should be meaningful and reflect the intent behind the code. A name should answer the question, “What does this represent or do?”
Avoid Noise Words:
Avoid unnecessary words that do not add value or clarity, such as Manager
, Helper
, or Data
unless they provide meaningful context.
Length of Names:
Names should be long enough to be descriptive but not overly verbose. Strive for balance between brevity and clarity.
Contextual Naming: Names should provide context when needed, especially in large or complex codebases. Adding prefixes or suffixes can help, but avoid excessive qualification.
Variables and Properties:
Use camelCase for variable and property names.
Constants:
Use UPPER_SNAKE_CASE for constants.
Functions and Methods:
Use camelCase for function and method names. Start with a verb to indicate action.
Classes and Types:
Use PascalCase for class and type names, with each word capitalized.
Interfaces:
Prefix interfaces with an “I” in languages like C# or TypeScript, or use PascalCase in languages that don’t follow this convention.
Namespaces and Modules:
Use PascalCase for namespaces and modules. Ensure names reflect their content or purpose.
Files and Folders:
Use kebab-case or snake_case for file and folder names, particularly in web projects or where the language does not enforce case sensitivity.
Enums: Use PascalCase for enum names and UPPER_SNAKE_CASE for enum values.