engineering-discipline

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Engineering Discipline

工程规范

Duyetbot's engineering principles for code that scales to 10,000+ users.
Duyetbot 针对支持10000+用户规模代码的工程原则。

Core Rules

核心准则

1. No Shortcuts

1. 拒绝捷径

  • Every solution must be sustainable long-term
  • Temporary fixes become permanent debt
  • If it feels like a workaround, it is
  • 每个解决方案必须具备长期可持续性
  • 临时修复会演变为永久性技术债务
  • 若感觉是权宜之计,那它就是权宜之计

2. Minimal Changes

2. 最小化变更

  • One logical change per commit
  • Touch only what's necessary
  • Edit over Write (preserve context)
  • 每次提交仅包含一个逻辑变更
  • 仅修改必要内容
  • 优先编辑而非重写(保留上下文)

3. Verify Before Complete

3. 完成前先验证

  • Tests pass
  • Lint clean
  • Manual verification when needed
  • 测试全部通过
  • 代码检查无问题
  • 必要时进行人工验证

Quality Gates

质量关卡

Before marking any work complete:
在标记任何工作完成前,需满足以下要求:

Code

代码

  • No errors/warnings
  • Follows existing patterns
  • No hardcoded values
  • Error handling present
  • Input validation at boundaries
  • 无错误/警告
  • 遵循现有代码模式
  • 无硬编码值
  • 包含错误处理逻辑
  • 在边界处进行输入验证

Testing

测试

  • Unit tests for logic
  • Integration tests for flows
  • Edge cases covered
  • Tests are deterministic
  • 为业务逻辑编写单元测试
  • 为流程编写集成测试
  • 覆盖边缘场景
  • 测试结果可复现

Performance

性能

  • No N+1 patterns
  • Appropriate caching
  • Resource cleanup
  • 无N+1查询问题
  • 合理使用缓存
  • 资源已清理

Security

安全

  • Input sanitized
  • Auth/authz checked
  • No secrets in code
  • 输入已做净化处理
  • 已检查认证/授权逻辑
  • 代码中无敏感信息

Decision Rules

决策准则

When to Refactor

何时重构

Refactor when:
  • Adding features is painful
  • Bugs cascade
  • Code confuses
Don't when:
  • Code works, rarely changes
  • No immediate need
满足以下情况时进行重构:
  • 添加新功能变得困难
  • 漏洞接连出现
  • 代码难以理解
以下情况无需重构:
  • 代码运行正常且极少变更
  • 无即时需求

When to Abstract

何时抽象

Abstract when:
  • Pattern appears 3+ times
  • Abstraction reduces complexity
Don't when:
  • Only 1-2 occurrences
  • Abstraction more complex
满足以下情况时进行抽象:
  • 模式重复出现3次及以上
  • 抽象可降低复杂度
以下情况无需抽象:
  • 仅出现1-2次
  • 抽象反而增加复杂度

Anti-Patterns

反模式

BadWhyGood
Magic numbersUnclearNamed constants
God objectsUnmaintainableSingle responsibility
Copy-pasteBug multiplicationExtract shared
Commented codeConfusionGit history
Premature optimizationWrong focusMeasure first
不良做法原因正确做法
魔法数字含义模糊命名常量
上帝对象难以维护单一职责原则
复制粘贴漏洞会重复出现提取共享逻辑
注释掉的代码造成混淆查看Git历史
过早优化偏离核心目标先做性能度量