clean-code-principles
Skill0 starsChanged 3 months agoMITView on GitHub
整洁代码原则:命名、函数设计、SOLID、错误处理、格式化.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- davidanthonyn/claude-skillstheir own version, first seen Oct 20, 2026
- emvnuel/skillstheir own version, first seen Dec 27, 2025
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- emvnuel/skills★ 2same name
- davidanthonyn/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository219 other files it gives its agents.
- agent-doctrineSkill
- agent-evaluation-frameworkSkill
- agent-visualization-flintSkill
- hermes-agentSkill
- bailian-cliSkill
- edge-browser-automationSkill
- computer-useSkill
- jupyter-live-kernelSkill
- backup-strategiesSkill
- browser-automationSkill
- chinese-ai-free-apiSkill
- cicd-pipeline-templatesSkill
- copybaraSkill
- devops-toolkitSkill
- email-deliverabilitySkill
- monitoring-observabilitySkill
- obsidian-maintenanceSkill
- obsidian-troubleshootingSkill
- openclaw-windowsSkill
- openclaw-workerSkill
- webhook-subscriptionsSkill
- windows-dev-environmentSkill
- windows-masterSkill
- zero-downtime-deploySkill
- codebase-inspectionSkill
- github-workflowSkill
- adaptive-communicationSkill
- agent-cost-dashboardSkill
- agent-evolutionSkill
- agent-governanceSkill
- agent-osSkill
- context-efficient-toolsSkill
- context-loss-awarenessSkill
- creative-synthesisSkill
- hermes-desktop-pluginsSkill
- emotional-intelligenceSkill
- graph-engineering-workflowSkill
- hermes-maintenanceSkill
- hermes-voiceSkill
- hermes-hygieneSkill
- identity-coreSkill
- income-loopSkill
- master-synthesisSkill
- meta-cognitionSkill
- reasoning-engineSkill
- self-preservationSkill
- teaching-abilitySkill
- temporal-awarenessSkill
- hermes-themesSkill
- thinking-visualizationSkill
- user-modelingSkill
- voice-full-restoreSkill
- knowledge-graph-traversalSkill
- mcp-browser-canvasSkill
- free-api-gatewaySkill
- native-mcpSkill
- web-reverse-apiSkill
- ai-edaSkill
- huggingface-hubSkill
- industrial-ai-siemens-mcpSkill
- The first 60 shown.
The file
Files
整洁代码原则
借鉴 ryanmcdermott/clean-code-javascript (95k⭐) + Clean Code (Robert C. Martin)。
一、变量命名
有意义的名字
❌ const d = new Date();
✓ const currentDate = new Date();
同一个概念用同一个词
❌ getUserInfo() / getClientData() / getCustomerRecord()
✓ 统一用 getUser()
可搜索的名字
❌ setTimeout(blastOff, 86400000) — 86400000 是什么?
✓ const MILLISECONDS_IN_A_DAY = 86400000; setTimeout(blastOff, MILLISECONDS_IN_A_DAY);
不要用魔法数字
❌ if (status === 3) — 3 是什么意思?
✓ if (status === ORDER_CANCELLED)
布尔变量用 is/has/can 前缀
isLoading, hasError, canSubmit
二、函数设计
一个函数只做一件事
❌ 一个函数里:验证参数 + 查数据库 + 格式化输出 + 发邮件 ✓ 拆成 4 个函数,各做各的
参数越少越好(最多 3 个)
❌ createUser(name, email, age, address, phone, company)
✓ createUser({ name, email, age, address, phone, company }) — 用对象传参
无副作用(不偷偷改全局状态)
❌
let counter = 0;
function increment() { counter++; } // 副作用:改了全局变量✓
function increment(value) { return value + 1; } // 纯函数不要用 flag 参数
❌ render(true) — true 是什么意思?
✓ renderAsAdmin() / renderAsUser()
优先 return early(早返回,少嵌套)
❌
if (user) {
if (user.isActive) {
if (user.hasPermission) { doSomething(); }
}
}✓
if (!user) return;
if (!user.isActive) return;
if (!user.hasPermission) return;
doSomething();三、SOLID 原则
S — 单一职责
一个类/函数只做一件事,只有一个被修改的理由。
O — 开闭原则
对扩展开放,对修改封闭。加新功能 → 加新代码,不改旧代码。
L — 里氏替换
子类必须能替换父类,不破坏程序正确性。
I — 接口隔离
接口要小而专,不要大而全。不强迫客户端依赖它不用的方法。
D — 依赖倒置
依赖抽象(接口),不依赖具体实现。高层模块不依赖低层模块。
四、错误处理
不要忽略错误
❌ try { doSomething(); } catch(e) {} — 错误被吃了!
✓ 至少 console.error(e) 或 log
不要用错误码
❌ if (result === -1) — -1 是什么意思?
✓ 抛异常或返回 Result 类型
异常要具体
❌ catch (Exception e) — 太宽泛
✓ catch (FileNotFoundError e) / catch (ConnectionError e)
五、注释原则
解释"为什么",不是"是什么"
❌ // 将 age 加 1(代码本身说了)
✓ // 年龄加1,因为新算法需要排除新生儿(年龄=0)的特殊情况
不要用注释掩盖坏代码
❌ 写一大段注释解释为什么这段代码这么复杂 ✓ 重构代码让它自己说话
删除注释掉的代码
❌ // oldFunction(); // 先注释掉,以后可能用
✓ 删掉!git 历史里有。
六、代码格式化
团队统一格式化工具
- Python:black / ruff
- JS/TS:prettier
- C/C++:clang-format
- 不纠结风格,工具说了算
垂直密度
相关代码放一起,不同概念空行分开。
水平长度
一行不超过 80-120 字符。
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

