npx skills add https://github.com/mindrally/skills --skill general-best-practices一份全面的软件开发最佳实践合集,适用于各种技术栈和项目类型。
编写简短、专注且具有单一职责的函数。
为变量、函数和类使用清晰、描述性的名称。
避免深层嵌套;优先使用提前返回和守卫子句。
保持函数和方法在合理长度内(通常不超过 30 行)。
始终显式处理错误,而不是静默忽略它们。
使用包装错误以提高可追溯性和上下文信息。
提供有助于调试的有意义的错误消息。
在开发过程中快速失败并明确报告失败。
将代码组织成逻辑模块和包。
分离关注点:将业务逻辑与基础设施代码分开。
使用一致的文件和文件夹命名约定。
在 API 设计中遵循最小意外原则。
将代码结构划分为不同的层次:
优先使用组合而非继承。
面向接口编程,而非实现。
使用依赖注入以提高可测试性和灵活性。
为变化而设计:隔离业务逻辑并最小化框架锁定。
在适当的地方应用 SOLID 原则。
编写快速、隔离且可重复的测试。
使用表驱动测试来测试多种场景。
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
清晰地模拟外部依赖。
目标是业务关键代码的高测试覆盖率。
测试组件与外部系统之间的交互。
使用单独的测试配置和数据库。
每次测试运行后清理测试数据。
将快速的单元测试与较慢的集成测试分开。
在开发过程中频繁运行快速测试。
在 CI/CD 流水线中包含测试。
在服务边界验证所有输入。
永远不要信任用户输入;对所有内容进行净化和验证。
使用参数化查询以防止 SQL 注入。
为令牌和会话使用安全默认设置。
在每一层实施适当的访问控制。
安全地存储密钥;切勿将其提交到版本控制。
对所有通信使用 HTTPS。
实施速率限制以防止滥用。
为外部服务调用使用熔断器。
先分析再优化;避免过早优化。
定期进行测量和基准测试。
关注热点路径和频繁执行的代码。
在关键路径上最小化内存分配。
为数据库和网络连接使用连接池。
实施适当的资源清理和释放。
缓存昂贵的计算和频繁访问的数据。
使用适当的缓存失效策略。
考虑缓存一致性和新鲜度要求。
使用结构化日志记录(生产环境使用 JSON 格式)。
包含相关上下文:请求 ID、用户 ID、时间戳。
使用适当的日志级别:DEBUG、INFO、WARN、ERROR。
避免记录敏感信息。
跟踪关键指标:延迟、吞吐量、错误率。
为异常和阈值违规设置警报。
使用仪表板来了解系统健康状况。
为微服务实现分布式追踪。
跨服务边界传播追踪上下文。
在跨度中记录重要属性以便调试。
使用清晰的描述记录公共 API。
解释“为什么”,而不仅仅是“是什么”。
将文档保存在其描述的代码附近。
代码更改时更新文档。
维护一个包含设置说明的清晰 README。
记录架构决策(ADRs)。
为团队成员提供贡献指南。
编写清晰、简洁的提交信息。
进行原子提交,代表一个单一的逻辑变更。
保持提交内容小而专注。
为新开发使用功能分支。
保持主分支稳定且可部署。
在合并到主分支前进行代码审查。
在每次提交时自动运行测试。
强制执行代码格式化和代码检查。
在流水线中包含安全扫描。
在团队中使用一致的开发环境。
记录设置步骤和先决条件。
自动化常见的开发任务。
每周安装次数
115
仓库
GitHub 星标数
42
首次出现
2026年1月25日
安全审计
安装于
gemini-cli97
opencode96
codex92
github-copilot89
cursor87
amp80
A comprehensive collection of software development best practices applicable across various technology stacks and project types.
Write short, focused functions with a single responsibility.
Use clear, descriptive names for variables, functions, and classes.
Avoid deep nesting; prefer early returns and guard clauses.
Keep functions and methods to a reasonable length (typically under 30 lines).
Always handle errors explicitly rather than silently ignoring them.
Use wrapped errors for traceability and context.
Provide meaningful error messages that help with debugging.
Fail fast and fail loudly during development.
Organize code into logical modules and packages.
Separate concerns: keep business logic separate from infrastructure code.
Use consistent file and folder naming conventions.
Follow the principle of least surprise in API design.
Structure code into distinct layers:
Prefer composition over inheritance.
Program to interfaces, not implementations.
Use dependency injection for testability and flexibility.
Design for change: isolate business logic and minimize framework lock-in.
Apply SOLID principles where appropriate.
Write tests that are fast, isolated, and repeatable.
Use table-driven tests for testing multiple scenarios.
Mock external dependencies cleanly.
Aim for high test coverage of business-critical code.
Test interactions between components and external systems.
Use separate test configurations and databases.
Clean up test data after each test run.
Separate fast unit tests from slower integration tests.
Run fast tests frequently during development.
Include tests in CI/CD pipelines.
Validate all inputs at service boundaries.
Never trust user input; sanitize and validate everything.
Use parameterized queries to prevent SQL injection.
Use secure defaults for tokens and sessions.
Implement proper access control at every layer.
Store secrets securely; never commit them to version control.
Use HTTPS for all communications.
Implement rate limiting to prevent abuse.
Use circuit breakers for external service calls.
Profile before optimizing; avoid premature optimization.
Measure and benchmark regularly.
Focus on hot paths and frequently executed code.
Minimize memory allocations in critical paths.
Use connection pooling for database and network connections.
Implement proper resource cleanup and disposal.
Cache expensive computations and frequently accessed data.
Use appropriate cache invalidation strategies.
Consider cache consistency and freshness requirements.
Use structured logging (JSON format for production).
Include relevant context: request IDs, user IDs, timestamps.
Log at appropriate levels: DEBUG, INFO, WARN, ERROR.
Avoid logging sensitive information.
Track key metrics: latency, throughput, error rates.
Set up alerts for anomalies and threshold violations.
Use dashboards for visibility into system health.
Implement distributed tracing for microservices.
Propagate trace context across service boundaries.
Record important attributes in spans for debugging.
Document public APIs with clear descriptions.
Explain the "why" not just the "what".
Keep documentation close to the code it describes.
Update documentation when code changes.
Maintain a clear README with setup instructions.
Document architecture decisions (ADRs).
Provide contribution guidelines for team members.
Write clear, concise commit messages.
Make atomic commits that represent a single logical change.
Keep commits small and focused.
Use feature branches for new development.
Keep the main branch stable and deployable.
Review code before merging to main.
Run tests automatically on every commit.
Enforce code formatting and linting.
Include security scanning in the pipeline.
Use consistent development environments across the team.
Document setup steps and prerequisites.
Automate common development tasks.
Weekly Installs
115
Repository
GitHub Stars
42
First Seen
Jan 25, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
gemini-cli97
opencode96
codex92
github-copilot89
cursor87
amp80
任务估算指南:敏捷开发故事点、计划扑克、T恤尺码法详解
10,500 周安装