Modular Code Organization
Write modular Python code with files sized for maintainability and AI-assisted development.
| Lines | Status | Action |
|---|---|---|
| 150-500 | Optimal | Sweet spot for AI code editors and human comprehension |
| 500-1000 | Large | Look for natural split points |
| 1000-2000 | Too large | Refactor into focused modules |
| 2000+ | Critical | Must split - causes tooling issues and cognitive overload |
Split when ANY of these apply:
auth.py → auth/login.py, auth/tokens.py, auth/permissions.pyfeature/
├── __init__.py # Keep minimal, just exports
├── core.py # Main logic (under 500 lines)
├── models.py # Data structures
├── handlers.py # I/O and side effects
└── utils.py # Pure helper functions
data_storage.py not utils2.py)__init__.py files minimal or emptyWhen splitting an existing large file:
Files over 2000 lines that need attention:
PyTorch深度学习模式与最佳实践,用于构建稳健、高效且可复现的训练流程、模型架构和数据加载。