coding-practices
编码实践,包括错误处理、输入验证、日志记录、自解释代码和 DRY 原则。在编写代码、处理错误或改进代码质量时使用。
📖 中文导读:编码实践,包括错误处理、输入验证、日志记录、自解释代码和 DRY 原则。在编写代码、处理错误或改进代码质量时使用。 以下正文为该技能的原始 SKILL.md 内容(英文),上方安装命令可直接使用。
name: coding-practices description: Code quality practices: error handling, validation, logging, and DRY. Use when writing or reviewing code.
Coding Practices
Guidelines for writing maintainable, robust, and self-documenting code.
Quick Start
// Self-documenting with proper error handling
function createUser(email: string, age: number): User {
if (!email.includes("@")) throw new Error("Invalid email");
if (age < 0 || age > 150) throw new Error("Invalid age");
return { email, age };
}
Key Principles
- Use meaningful names (self-documenting code)
- Comments explain "why", not "what"
- DRY: abstract when used 3+ times
- Validate all input data
- Handle all error cases with proper Error objects
- Never ignore errors
- Use named constants instead of magic values
- Avoid circular dependencies
References
See rules.md for complete guidelines with examples.