Variable and Function Names:
- Use descriptive and meaningful names that reflect the purpose or functionality of the variable or function.
- Start variable and function names with a lowercase letter.
- For multi-word names, use camelCase, where each word (except the first) is capitalized, e.g.,
- Use uppercase letters for constant names.
- Separate words with underscores, e.g.,
- Use PascalCase, where the first letter of each word is capitalized, for constructor names.
- Constructors are typically used to create objects, so they are often named using nouns or noun phrases, e.g.,
- Use PascalCase for class names, similar to constructor names.
- Classes represent blueprints for creating objects, so they are often named using nouns or noun phrases, e.g.,
Module and File Names:
- Use lowercase letters for module and file names.
- Separate words with hyphens or underscores, e.g.,
- Avoid using global variables as much as possible. When needed, prefix them with a unique identifier to avoid naming conflicts.
- For example, if your project is named "MyApp," you could use
Naming Conventions for Specific Cases:
- Event handlers: Use the prefix "on" followed by the event name, e.g.,
- Private variables or functions: Prefix them with an underscore, e.g.,
Remember that the most important aspect of naming conventions is consistency within your codebase. Consistently following a convention, even if it differs slightly from the ones mentioned above, will help maintain readability and make your code easier to work with.