Loading...
Loading...
Compare original and translation side by side
| Context | Pattern | Example |
|---|---|---|
| Config values | Single source of truth | Define DB connection in one env file, reference everywhere |
| Validation rules | Shared schema | Use JSON Schema or Zod schema for both client and server validation |
| API contracts | Generate from spec | OpenAPI spec generates types, docs, and client code |
| Business logic | Domain module | Tax calculation in one module, not scattered across controllers |
| Database schema | Migration-driven | Schema defined in migrations, ORM models generated from DB |
| 场景 | 模式 | 示例 |
|---|---|---|
| 配置值 | 单一可信源 | 在一个环境文件中定义数据库连接信息,在所有地方引用 |
| 验证规则 | 共享 schema | 使用JSON Schema或Zod schema同时用于客户端和服务端验证 |
| API 契约 | 从规范生成 | OpenAPI 规范用于生成类型、文档和客户端代码 |
| 业务逻辑 | 领域模块 | 税务计算逻辑集中在一个模块中,而非分散在各个控制器 |
| 数据库 schema | 迁移驱动 | schema在迁移中定义,ORM模型从数据库生成 |
| Context | Pattern | Example |
|---|---|---|
| Architecture | Layered separation | Controller -> Service -> Repository, each replaceable |
| Dependencies | Dependency injection | Pass a |
| Testing | Isolated unit tests | Test business logic without database, network, or filesystem |
| Configuration | Environment-driven | Feature flags in config, not |
| Deployment | Independent services | Deploy auth service without redeploying payment service |
| 场景 | 模式 | 示例 |
|---|---|---|
| 架构 | 分层分离 | 控制器 -> 服务 -> 仓库,每个层均可替换 |
| 依赖 | 依赖注入 | 传递 |
| 测试 | 独立单元测试 | 在不依赖数据库、网络或文件系统的情况下测试业务逻辑 |
| 配置 | 环境驱动 | 功能标志在配置中设置,而非业务逻辑中的 |
| 部署 | 独立服务 | 部署认证服务时无需重新部署支付服务 |
| Context | Pattern | Example |
|---|---|---|
| New project | Vertical slice | Build one feature end-to-end: button -> API -> DB -> response |
| Uncertain tech | Spike prototype | Test if WebSocket performance is sufficient before committing |
| Framework eval | Tracer through stack | Build login flow through the full framework before choosing it |
| Microservice | Walking skeleton | Deploy a hello-world service through the full CI/CD pipeline |
| Data pipeline | End-to-end flow | One record from ingestion through transformation to output |
| 场景 | 模式 | 示例 |
|---|---|---|
| 新项目 | 垂直切片 | 端到端构建一个功能:按钮 -> API -> 数据库 -> 响应 |
| 不确定技术 | 探索型原型 | 在投入之前测试WebSocket性能是否达标 |
| 框架评估 | 全栈追踪 | 在选择框架之前,通过完整框架构建登录流程 |
| 微服务 | 行走骨架 | 通过完整CI/CD管道部署一个hello-world服务 |
| 数据管道 | 端到端流程 | 一条记录从 ingestion 到转换再到输出的完整流程 |
| Context | Pattern | Example |
|---|---|---|
| Function entry | Precondition guard | |
| Function exit | Postcondition check | Verify returned list is sorted before returning |
| Class state | Invariant validation | |
| API boundary | Schema validation | Validate request body against schema before processing |
| Data pipeline | Stage assertions | Assert row count after ETL transform matches expectation |
| 场景 | 模式 | 示例 |
|---|---|---|
| 函数入口 | 前置条件守卫 | 函数开始处使用 |
| 函数出口 | 后置条件检查 | 返回前验证返回的列表已排序 |
| 类状态 | 不变量验证 | 每次状态变更后调用 |
| API 边界 | Schema 验证 | 处理前验证请求体符合schema |
| 数据管道 | 阶段断言 | ETL转换后断言行数符合预期 |
| Context | Pattern | Example |
|---|---|---|
| Legacy code | Board up windows | Wrap bad code in a clean interface before adding features |
| Code review | Zero-tolerance for new debt | Reject PRs that add |
| Tech debt | Debt budget | Allocate 20% of each sprint to fixing broken windows |
| New team member | Clean onboarding path | First task: fix a broken window to learn the codebase |
| Monitoring | Entropy metrics | Track linting violations, test coverage trends over time |
| 场景 | 模式 | 示例 |
|---|---|---|
| 遗留代码 | 封装破窗 | 在添加功能之前,用干净的接口包裹糟糕的代码 |
| 代码评审 | 零容忍新增债务 | 拒绝添加无工单的 |
| 技术债务 | 债务预算 | 每个 sprint 分配20%的时间用于修复破窗 |
| 新团队成员 | 整洁入职路径 | 第一个任务:修复一个破窗以熟悉代码库 |
| 监控 | 熵指标 | 随时间跟踪lint违规、测试覆盖率趋势 |
| Context | Pattern | Example |
|---|---|---|
| Database | Repository pattern | Business logic calls |
| External API | Adapter/wrapper | |
| Feature flags | Runtime toggles | New checkout flow behind a flag, rollback in seconds |
| Architecture | Event-driven decoupling | Services communicate via events, not direct HTTP calls |
| Deployment | Container abstraction | Dockerized app runs on AWS, GCP, or bare metal unchanged |
| 场景 | 模式 | 示例 |
|---|---|---|
| 数据库 | 仓库模式 | 业务逻辑调用 |
| 外部API | 适配器/包装器 | |
| 功能标志 | 运行时切换 | 新结账流程在标志后,可在几秒内回滚 |
| 架构 | 事件驱动解耦 | 服务通过事件通信,而非直接HTTP调用 |
| 部署 | 容器抽象 | 容器化应用可在AWS、GCP或裸金属上无修改运行 |
| Context | Pattern | Example |
|---|---|---|
| Sprint planning | Range estimates | "3-5 days" with confidence level, not a single number |
| New technology | Time-boxed spike | "I'll spend 2 days evaluating; then I can estimate properly" |
| Large project | Bottom-up decomposition | Break into tasks < 1 day, sum with buffer for integration |
| Learning | Weekly investment | 1 hour/week on a new language, tool, or domain |
| Career growth | Portfolio diversification | Mix of depth (expertise) and breadth (adjacent skills) |
| 场景 | 模式 | 示例 |
|---|---|---|
| Sprint规划 | 范围估算 | 给出「3-5天」及置信度,而非单一数字 |
| 新技术 | 时间盒探索 | 「我会花2天评估;之后就能给出准确估算」 |
| 大型项目 | 自底向上分解 | 分解为小于1天的任务,总和加上集成缓冲时间 |
| 学习 | 每周投资 | 每周花1小时学习新语言、工具或领域 |
| 职业发展 | 投资组合多元化 | 混合深度(专业技能)和广度(相邻技能) |
| Mistake | Why It Fails | Fix |
|---|---|---|
| DRY-ing similar-looking code that serves different purposes | Creates coupling between unrelated concepts; changes to one break the other | Only DRY knowledge, not coincidental code similarity |
| Skipping tracer bullets and building layer-by-layer | Integration issues surface late; no end-to-end feedback until the end | Build one thin vertical slice first |
| Ignoring broken windows "because we'll refactor later" | Entropy accelerates; later never comes; team morale drops | Fix immediately or board up with a tracked ticket |
| Estimates as single-point commitments | Creates false precision; erodes trust when missed | Always give ranges with confidence levels |
| Making everything "flexible" upfront | Over-engineering; YAGNI; abstraction without evidence of need | Add flexibility when you have concrete evidence you'll need it |
| Assertions in production removed "for performance" | Bugs that assertions would catch now silently corrupt data | Keep critical assertions; benchmark before removing any |
| Global state "for convenience" | Destroys orthogonality; every module coupled to everything | Use dependency injection and explicit parameters |
| 错误 | 失败原因 | 修复方案 |
|---|---|---|
| 对服务于不同目的的相似代码应用DRY原则 | 会在不相关概念之间创建耦合;变更其中一个会破坏另一个 | 仅对知识应用DRY,而非巧合的代码相似性 |
| 跳过追踪代码,逐层构建 | 集成问题很晚才暴露;直到最后才得到端到端反馈 | 先构建一个垂直切片再扩展 |
| 忽视破窗「因为以后会重构」 | 熵增加速;「以后」永远不会到来;团队士气下降 | 立即修复或用跟踪工单封起来 |
| 估算作为单点承诺 | 造成虚假精度;未达标时会损害信任 | 始终给出带置信度的范围 |
| 提前让所有内容「灵活」 | 过度设计;违反YAGNI;无需求依据的抽象 | 当有明确证据需要时再添加灵活性 |
| 为了「性能」在生产环境移除断言 | 断言本可以捕获的bug现在会默默损坏数据 | 保留关键断言;在移除前先做基准测试 |
| 为了「方便」使用全局状态 | 破坏正交性;每个模块都与所有内容耦合 | 使用依赖注入和显式参数 |
| Question | If No | Action |
|---|---|---|
| Can I change the database without touching business logic? | Orthogonality violation | Introduce repository/adapter pattern |
| Do I have an end-to-end slice working? | Missing tracer bullet | Build one vertical slice before expanding |
| Is every business rule defined in exactly one place? | DRY violation | Identify the authoritative source and remove duplicates |
| Would a new developer call this codebase "clean"? | Broken windows present | Schedule a dedicated cleanup sprint |
| Do my estimates include ranges and confidence levels? | Estimation problem | Switch to PERT or range-based estimates |
| Can I roll back this deployment in under 5 minutes? | Reversibility gap | Add feature flags and blue-green deploys |
| Am I learning something new every week? | Knowledge portfolio stagnant | Schedule weekly learning time and track it |
| 问题 | 如果答案为否 | 行动 |
|---|---|---|
| 我可以在不修改业务逻辑的情况下更换数据库吗? | 违反正交性 | 引入仓库/适配器模式 |
| 我有一个可用的端到端切片吗? | 缺少追踪代码 | 在扩展之前构建一个垂直切片 |
| 每个业务规则都只在一个地方定义吗? | 违反DRY原则 | 确定权威源并移除重复 |
| 新开发者会认为这个代码库「干净」吗? | 存在破窗 | 安排专门的清理sprint |
| 我的估算包含范围和置信度吗? | 估算问题 | 切换到PERT或基于范围的估算 |
| 我能在5分钟内回滚这个部署吗? | 可逆转性不足 | 添加功能标志和蓝绿部署 |
| 我每周都在学习新东西吗? | 知识体系停滞 | 安排每周学习时间并跟踪 |