Code-Memo

Naming Conventions

General Principles of Naming Conventions

  1. 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.

  2. Consistency:

    Follow a consistent naming pattern across the entire codebase. Consistency aids readability and makes the code easier to navigate.

  3. Avoid Abbreviations:

    Avoid using abbreviations or acronyms unless they are widely understood within the team or industry.

  4. 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?”

  5. Avoid Noise Words:

    Avoid unnecessary words that do not add value or clarity, such as Manager, Helper, or Data unless they provide meaningful context.

  6. Length of Names:

    Names should be long enough to be descriptive but not overly verbose. Strive for balance between brevity and clarity.

  7. Contextual Naming: Names should provide context when needed, especially in large or complex codebases. Adding prefixes or suffixes can help, but avoid excessive qualification.

Common Naming Conventions

  1. Variables and Properties:

    Use camelCase for variable and property names.

  2. Constants:

    Use UPPER_SNAKE_CASE for constants.

  3. Functions and Methods:

    Use camelCase for function and method names. Start with a verb to indicate action.

  4. Classes and Types:

    Use PascalCase for class and type names, with each word capitalized.

  5. Interfaces:

    Prefix interfaces with an “I” in languages like C# or TypeScript, or use PascalCase in languages that don’t follow this convention.

  6. Namespaces and Modules:

    Use PascalCase for namespaces and modules. Ensure names reflect their content or purpose.

  7. 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.

  8. Enums: Use PascalCase for enum names and UPPER_SNAKE_CASE for enum values.