coding-guideline

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Coding Guidelines

Coding Guidelines

  • Think first:不假设、不藏疑、不沉默地选边。拿不准就问;有多种理解就全摆出来;有更简单的做法就直说。
  • KISS:只写解决问题所需的最少代码——不加功能、不加抽象、不防御不可能的场景。200 行能压成 50 行就重写。
  • DRY:重复三次再抽象;两次就复制,别提前造轮子。
  • Boy Scout Rule:离开代码时比来时干净一点——只清理你碰到的代码,不顺手重构无关部分。
  • Test first:把任务翻译成可验证的目标——"修 bug" → 先写复现测试,再让它通过。跑过才算完成,"应该没问题"不是结论。
  • Self-review:review changes to find:
    • 边界:重入、重启恢复、空值。
    • 并发:共享状态、死锁、channel 泄漏
    • 坏味道:函数过长、嵌套过深、命名含糊
  • Think first: Don't make assumptions, don't hide doubts, don't take sides silently. Ask if you're unsure; present all interpretations if there are multiple; speak up if there's a simpler approach.
  • KISS: Write only the minimal code needed to solve the problem—no extra features, no unnecessary abstractions, no defensive coding for impossible scenarios. Rewrite if you can compress 200 lines into 50.
  • DRY: Abstract only after repeating three times; copy twice, don't reinvent the wheel prematurely.
  • Boy Scout Rule: Leave the code cleaner than you found it—only clean up the code you touch, don't refactor unrelated parts just because it's convenient.
  • Test first: Translate tasks into verifiable goals—"fix a bug" → first write a reproduction test, then make it pass. It's only done when it runs successfully; "it should be fine" is not a conclusion.
  • Self-review: Review changes to find:
    • Boundaries: Reentrancy, restart recovery, null values.
    • Concurrency: Shared state, deadlocks, channel leaks
    • Code smells: Long functions, excessive nesting, ambiguous naming