You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Guidelines for writing clean, maintainable, and human-readable code. Apply these rules when writing or reviewing code to ensure consistency and quality.
2
+
description: Comprehensive guide to Robert C. Martin's Clean Code principles for writing maintainable, readable code that expresses intent clearly
3
3
globs:
4
4
alwaysApply: false
5
5
---
6
-
# Clean Code Guidelines
7
-
8
-
## Constants Over Magic Numbers
9
-
- Replace hard-coded values with named constants
10
-
- Use descriptive constant names that explain the value's purpose
11
-
- Keep constants at the top of the file or in a dedicated constants file
12
-
13
-
## Meaningful Names
14
-
- Variables, functions, and classes should reveal their purpose
15
-
- Names should explain why something exists and how it's used
- Don't comment on what the code does - make the code self-documenting
20
-
- Use comments to explain why something is done a certain way
21
-
- Document APIs, complex algorithms, and non-obvious side effects
22
-
23
-
## Single Responsibility
24
-
- Each function should do exactly one thing
25
-
- Functions should be small and focused
26
-
- If a function needs a comment to explain what it does, it should be split
27
-
28
-
## DRY (Don't Repeat Yourself)
29
-
- Extract repeated code into reusable functions
30
-
- Share common logic through proper abstraction
31
-
- Maintain single sources of truth
32
-
33
-
## Clean Structure
34
-
- Keep related code together
35
-
- Organize code in a logical hierarchy
36
-
- Use consistent file and folder naming conventions
37
-
38
-
## Encapsulation
39
-
- Hide implementation details
40
-
- Expose clear interfaces
41
-
- Move nested conditionals into well-named functions
42
-
43
-
## Code Quality Maintenance
44
-
- Refactor continuously
45
-
- Fix technical debt early
46
-
- Leave code cleaner than you found it
47
-
48
-
## Testing
49
-
- Write tests before fixing bugs
50
-
- Keep tests readable and maintainable
51
-
- Test edge cases and error conditions
52
-
53
-
## Version Control
54
-
- Write clear commit messages
55
-
- Make small, focused commits
56
-
- Use meaningful branch names
6
+
# Clean Code Principles
7
+
8
+
A comprehensive guide to writing clean, maintainable, and readable code based on Robert C. Martin's "Clean Code" principles. These rules focus on creating code that clearly expresses intent, is easy to understand, modify, and maintain over time.
9
+
10
+
## Context
11
+
12
+
Provide guidelines for writing code that prioritizes readability, simplicity, and maintainability over cleverness or optimization.
13
+
14
+
*Applies to:* All software development projects, code reviews, refactoring efforts
15
+
*Level:* Tactical/Operational - direct application in daily coding practices
16
+
*Audience:* All developers, from junior to senior levels
17
+
18
+
## Core Principles
19
+
20
+
1. *Clarity over Cleverness:* Code should be written to be read and understood by humans first, machines second
21
+
2. *Express Intent:* Names, functions, and structure should clearly communicate what the code does and why
22
+
3. *Simplicity:* Prefer simple, straightforward solutions over complex, over-engineered ones
23
+
4. *Single Responsibility:* Each unit of code should have one clear purpose and reason to change
24
+
5. *Leave it Better:* Always improve code when you touch it, following the Boy Scout Rule
25
+
26
+
## Rules
27
+
28
+
### Must Have (Critical)
29
+
30
+
- *RULE-001:* Use meaningful, pronounceable names for variables, functions, classes, and modules
31
+
- *RULE-002:* Functions must be small (ideally <20 lines) and do one thing well
0 commit comments