Code Quality Standards
Enforce best practices for writing clean, maintainable, and high-quality code across all programming languages.
Instructions
When writing or reviewing code, follow these guidelines:
1. Code Writing Standards
Follow established language-specific conventions for spacing, indentation, and formattingAdhere to internal project rules for folder structure and naming patternsMaintain consistency with the existing codebase styleUse language-appropriate idioms and patterns2. Comment Usage
Use comments sparingly and only when necessaryWrite meaningful comments that explain "why" not "what"Avoid commenting on obvious code behaviorDocument unusual behavior, workarounds, or non-intuitive logicRemove outdated or redundant comments during refactoring3. Conditional Logic
Encapsulate nested if/else statements into well-named functionsUse descriptive function names that clearly indicate the condition being checkedExtract complex boolean expressions into named variables or functionsPrefer early returns to reduce nesting depth4. DRY Principle (Don't Repeat Yourself)
Identify and eliminate code duplicationExtract repeated logic into reusable functions, classes, or modulesUse appropriate abstraction levels (functions, classes, modules, libraries)Ensure changes only need to be made in one placeBalance DRY with readability—avoid premature abstraction5. Function Design
Write short, focused functions following the Single Responsibility PrincipleEach function should do one thing wellBreak complex or long functions into smaller, composable unitsAim for functions that fit on one screen without scrollingLimit function parameters (ideally 3 or fewer)6. Naming Conventions
Use meaningful, descriptive names for all identifiersNames should clearly indicate purpose and behaviorAvoid abbreviations unless universally understoodUse consistent naming patterns throughout the codebaseNames should eliminate the need for explanatory commentsFollow language-specific naming conventions (camelCase, snake_case, PascalCase)7. Code Structure & Maintainability
Write code that is easy to read and understandPrioritize clarity over clevernessStructure code logically with clear separation of concernsRegularly review and refactor to improve qualityKeep related code togetherRemove dead code and unused imports8. Version Control Practices
Use Git or equivalent version control systemWrite clear, descriptive commit messagesMake small, focused commitsReview changes before committingExamples
**Bad - Nested conditionals:**
```javascript
if (user) {
if (user.isActive) {
if (user.hasPermission) {
// do something
}
}
}
```
**Good - Extracted function:**
```javascript
function canPerformAction(user) {
return user && user.isActive && user.hasPermission;
}
if (canPerformAction(user)) {
// do something
}
```
**Bad - Unclear naming:**
```javascript
function calc(a, b) {
return a * b * 0.2;
}
```
**Good - Descriptive naming:**
```javascript
function calculateTaxAmount(subtotal, quantity) {
const TAX_RATE = 0.2;
return subtotal * quantity * TAX_RATE;
}
```
Constraints
Apply these standards consistently across the entire codebaseBalance perfection with pragmatism—not every line needs refactoringConsider team conventions and existing patterns before making changesPrioritize readability and maintainability over premature optimization