Modular Code

parcadei/continuous-claude-v3/.claude/skills/modular-code

作者 parcadeid07ff4b06b62无许可证3.9K 个星标收录于 2026年10月8日更新于 2026年10月8日仓库8个月前更新

Modular Code Organization

AI 生成的概览

指导将 Python 代码拆分为便于维护和 AI 辅助编辑的模块化文件。

功能
提供组织 Python 代码为模块的准则,包括文件行数阈值、何时拆分文件的判断标准,以及按领域概念、抽象层、数据类型和 I/O 边界等自然拆分点。还给出包结构建议以及模块命名和组织的注意事项。包含拆分现有大文件的重构流程,并列出代码库中的候选文件。
适用场景
适用于将 Python 代码组织或重构为模块、判断文件是否过大,或规划如何拆分现有大文件时。其目标是提升可维护性和支持 AI 辅助开发。
运行要求
无需工具、软件包或凭据;仅为说明性指令,不附带脚本。

Modular Code Organization

Write modular Python code with files sized for maintainability and AI-assisted development.

File Size Guidelines

LinesStatusAction
150-500OptimalSweet spot for AI code editors and human comprehension
500-1000LargeLook for natural split points
1000-2000Too largeRefactor into focused modules
2000+CriticalMust split - causes tooling issues and cognitive overload

When to Split

Split when ANY of these apply:

  • File exceeds 500 lines
  • Multiple unrelated concerns in same file
  • Scroll fatigue finding functions
  • Tests for the file are hard to organize
  • AI tools truncate or miss context

How to Split

Natural Split Points

  1. By domain concept: auth.py → auth/login.py, auth/tokens.py, auth/permissions.py
  2. By abstraction layer: Separate interface from implementation
  3. By data type: Group operations on related data structures
  4. By I/O boundary: Isolate database, API, file operations

Package Structure

feature/├── __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

DO

  • Use meaningful module names (data_storage.py not utils2.py)
  • Keep __init__.py files minimal or empty
  • Group related functions together
  • Isolate pure functions from side effects
  • Use snake_case for module names

DON'T

  • Split files arbitrarily by line count alone
  • Create single-function modules
  • Over-modularize into "package hell"
  • Use dots or special characters in module names
  • Hide dependencies with "magic" imports

Refactoring Large Files

When splitting an existing large file:

  1. Identify clusters: Find groups of related functions
  2. Extract incrementally: Move one cluster at a time
  3. Update imports: Fix all import statements
  4. Run tests: Verify nothing broke after each move
  5. Document: Update any references to old locations

Current Codebase Candidates

Files over 2000 lines that need attention:

  • Math compute modules (scipy, mpmath, numpy) - domain-specific, may be acceptable
  • patterns.py - consider splitting by pattern type
  • memory_backfill.py - consider splitting by operation type

Sources

来源与署名

来源:parcadei/continuous-claude-v3位于.claude/skills/modular-code提交d07ff4b

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架