No. 108 Lower the entropy

Clean Code Guidelines

Use when the code works but the structure is harder than the behavior

  • Claude Code
  • Codex
  • Cursor
  • Lower the entropy

Prompt

# Clean Code Guidelines

## Constants Over Magic Numbers
- Replace hard-coded values with named constants
- Use descriptive constant names that explain the value's purpose
- Keep constants at the top of the file or in a dedicated constants file

## Meaningful Names
- Variables, functions, and classes should reveal their purpose
- Names should explain why something exists and how it's used
- Avoid abbreviations unless they're universally understood

## Smart Comments
- Don't comment on what the code does - make the code self-documenting
- Use comments to explain why something is done a certain way
- Document APIs, complex algorithms, and non-obvious side effects

## Single Responsibility
- Each function should do exactly one thing
- Functions should be small and focused
- If a function needs a comment to explain what it does, it should be split

## DRY (Don't Repeat Yourself)
- Extract repeated code into reusable functions
- Share common logic through proper abstraction
- Maintain single sources of truth

## Clean Structure
- Keep related code together
- Organize code in a logical hierarchy
- Use consistent file and folder naming conventions

## Encapsulation
- Hide implementation details
- Expose clear interfaces
- Move nested conditionals into well-named functions

## Code Quality Maintenance
- Refactor continuously
- Fix technical debt early
- Leave code cleaner than you found it

## Testing
- Write tests before fixing bugs
- Keep tests readable and maintainable
- Test edge cases and error conditions

## Version Control
- Write clear commit messages
- Make small, focused commits
- Use meaningful branch names

When to use

“Clean Code Guidelines” fits when the code works but the structure is harder than the behavior, because it says “Clean Code Guidelines”, and it is written to stay in force on later turns rather than to finish one task.

With “Clean Code Guidelines” loaded, the user message can be as small as “fix the empty-cart total in src/cart.js and do not touch the test runner”, because “Clean Code Guidelines” is already in force.

When not to use

Leave “Clean Code Guidelines” unused when the change is a one-line typo or a red build you have not read, because “Clean Code Guidelines” points the other way

How to run it

Claude Code

Claude Code loads “Clean Code Guidelines” from .claude/rules on later sessions, so “Clean Code Guidelines” survives a new chat, which a one-off paste does not.

Codex

Codex keeps “Clean Code Guidelines” only if you put “Clean Code Guidelines” in AGENTS.md, or in AGENTS.override.md beside the directory that should inherit it. A paste that is not saved is gone next thread.

Cursor

Cursor keeps “Clean Code Guidelines” by saving “Clean Code Guidelines” as .cursor/rules. The chat transcript alone will not reload it tomorrow.

Comparison

Without “Clean Code Guidelines”, the model kept a single total function with inline fallbacks. With “Clean Code Guidelines”, it introduced named constants for the default price, default qty, and empty total, plus a lineTotal helper.

Related

来源:PatrickJS awesome-cursorrules · https://github.com/PatrickJS/awesome-cursorrules/blob/main/rules/clean-code.mdc · CC0-1.0 · 2026-12-01