Clear Naming Conventions
Guidelines for creating consistent, meaningful names in code
personal
## Guidelines for Clear Naming Conventions
1. **Core Principles:**
- Names should clearly communicate purpose and intent
- Consistency is key across the entire codebase
- Be specific rather than generic
- Prioritize readability over brevity (except for well-understood conventions)
- Follow established patterns in the language and framework
2. **Variables and Constants:**
- Use nouns or noun phrases that describe the data they contain
- Boolean variables should have prefixes like `is`, `has`, or `should`
- Avoid single-letter variables except for well-established conventions (e.g., `i` for loop indices)
- Use meaningful, searchable names (avoid ambiguous abbreviations)
- Constants should be in UPPER_SNAKE_CASE
3. **Functions and Methods:**
- Use verbs or verb phrases that describe the action performed
- Start with action words (e.g., `get`, `calculate`, `update`, `is`, `has`)
- Event handlers should start with `handle` or `on`
- Callback functions can be named with `cb` suffix when passed as arguments
- Express what they return or do, not how they work
4. **Components and Classes:**
- Use PascalCase for component and class names
- Name components after their primary responsibility
- Be specific about what they represent
- Higher-order components can use `with` prefix (e.g., `withAuth`)
- Custom hooks should start with `use` (e.g., `useFetch`)
5. **Files and Directories:**
- Use consistent casing (kebab-case for files is common in many projects)
- Group related files in descriptive directories
- Index files should export from a logical group
- Test files should clearly relate to what they're testing
6. **Language-Specific Conventions:**
- JavaScript/TypeScript: camelCase for variables/functions, PascalCase for classes/components
- CSS: kebab-case for class names and custom properties
- HTML: kebab-case for attributes, lowercase for elements
7. **Consistency Rule:**
- Follow existing patterns in the codebase even if they differ from your preference
- Document naming conventions to ensure team alignment
- Use linting tools to enforce consistency
Clear, descriptive names make code self-documenting, reducing the need for comments and making the codebase more maintainable for everyone.