Loading...
Loading...
Compare original and translation side by side
| File type | Soft limit | Hard limit | Action at hard limit |
|---|---|---|---|
| Source code (logic) | 150 lines | 300 lines | MUST split before proceeding |
| Test files | 200 lines | 400 lines | MUST split into focused test suites |
| Config / data | 100 lines | 200 lines | MUST split into per-concern configs |
| Documentation | 300 lines | 500 lines | MUST split into linked pages |
| 文件类型 | 软限制 | 硬限制 | 触发硬限制后的操作 |
|---|---|---|---|
| 源代码(逻辑层) | 150 行 | 300 行 | 必须先拆分再继续开发 |
| 测试文件 | 200 行 | 400 行 | 必须拆分为聚焦的测试套件 |
| 配置/数据文件 | 100 行 | 200 行 | 必须按关注点拆分为独立配置 |
| 文档 | 300 行 | 500 行 | 必须拆分为可互相链接的页面 |
"Can Claude read this file, its tests, and the files it directly depends on — all at once — without exceeding context or needing to compact?"
「Claude 能否同时读取这个文件、它的测试文件以及它直接依赖的所有文件,不超出上下文窗口限制,也不需要压缩内容?」
WRONG (layer-based):
controllers/user.ts
controllers/order.ts
services/user.ts
services/order.ts
models/user.ts
models/order.ts
RIGHT (feature-based):
user/controller.ts
user/service.ts
user/model.ts
order/controller.ts
order/service.ts
order/model.tsuser/WRONG (layer-based):
controllers/user.ts
controllers/order.ts
services/user.ts
services/order.ts
models/user.ts
models/order.ts
RIGHT (feature-based):
user/controller.ts
user/service.ts
user/model.ts
order/controller.ts
order/service.ts
order/model.tsuser/auth.tsauth/login.tsauth/register.tsauth/token.tsapi.tsapi/routes.tsapi/middleware.tsapi/validation.tsutils.tsstring-utils.tsdate-utils.tsarray-utils.tsauth.tsauth/login.tsauth/register.tsauth/token.tsapi.tsapi/routes.tsapi/middleware.tsapi/validation.tsutils.tsstring-utils.tsdate-utils.tsarray-utils.ts| Pattern | Problem | Fix |
|---|---|---|
| "God file" — one file does everything | Impossible to change safely | Split by responsibility |
| "Shotgun surgery" — one change touches 10+ files | Missing abstraction | Extract shared concern |
| "Barrel files" re-exporting everything | Hides dependency structure | Import directly from source |
| Premature abstraction for one use case | Unnecessary complexity | Three similar blocks > one premature abstraction |
| Layer-based organization | Unrelated files change together | Reorganize by feature |
| "Utils" or "helpers" grab-bag | No clear responsibility | Split by domain or delete |
| 反模式 | 问题 | 修复方案 |
|---|---|---|
| 「上帝文件(God file)」—— 单个文件承担所有职责 | 无法安全地做修改 | 按职责拆分 |
| 「霰弹式修改(Shotgun surgery)」—— 单次变更涉及10个以上的文件 | 缺少抽象 | 抽离公共关注点 |
| 「桶文件(Barrel files)」导出所有内容 | 隐藏依赖结构 | 直接从源文件导入 |
| 为单个使用场景提前做抽象 | 不必要的复杂度 | 三个相似的代码块 > 一个不成熟的抽象 |
| 按层级组织文件结构 | 不相关的文件会一起被修改 | 按功能重新组织 |
| 「Utils」或「helpers」大杂烩 | 没有清晰的职责 | 按领域拆分或者删除 |
| Excuse | Reality |
|---|---|
| "It's just one more function" | That's how 800-line files happen. Split now. |
| "Splitting will create too many files" | Many small files > few large files. Always. |
| "I'll refactor later" | You won't. The soft limit exists to prevent this. |
| "This file is the natural home for this" | If it exceeds the limit, it's not. Find a better home. |
| "It's all related" | Related is not the same as same-responsibility. |
| "The framework forces this structure" | Most frameworks work fine with smaller modules. Check. |
| 借口 | 现实 |
|---|---|
| 「就多加一个函数而已」 | 800行的大文件就是这么来的,现在就拆分。 |
| 「拆分后文件太多了」 | 多而小的文件永远好过少而大的文件。 |
| 「我以后再重构」 | 你不会的。软限制的存在就是为了避免这种情况。 |
| 「这个文件本来就该放这个逻辑」 | 如果它超出了大小限制,就不该放。找个更合适的位置。 |
| 「这些内容都是相关的」 | 相关不等于职责相同。 |
| 「框架强制要求这个结构」 | 绝大多数框架都支持更小的模块,核实一下。 |