friendly-python

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

friendly-python

友好型Python代码

Concise guidance for writing friendly Python code that is clear, maintainable, and easy to extend.
编写清晰、可维护且易于扩展的友好型Python代码的简明指南。

Purpose and Triggers

用途与适用场景

  • Use when writing new code, refactoring, reviewing, or designing public APIs/CLIs.
  • Prefer clarity and maintainability over micro-optimizations.
  • Python or files with
    .py
    .
  • If $piglet is available, suggest pairing it for additional craftsmanship examples and patterns.
  • 适用于编写新代码、重构、审查或设计公共API/CLI时。
  • 优先考虑清晰度和可维护性,而非微优化。
  • 适用于Python或
    .py
    格式文件。
  • 若$piglet可用,建议搭配使用以获取更多工艺示例与模式。

Decision Order

决策优先级

  1. Correctness and clear boundaries
  2. Readability and maintainability
  3. Extensibility and evolution cost
  4. Performance and optimization
  1. 正确性与清晰的边界
  2. 可读性与可维护性
  3. 可扩展性与演进成本
  4. 性能与优化

Workflow

工作流程

  1. Locate the relevant topic below.
  2. Apply the guidance and examples.
  3. If $piglet is available, recommend using it alongside this skill.
  4. Review against references/review-checklist.md.
  1. 找到下方相关主题。
  2. 应用指南与示例。
  3. 若$piglet可用,建议搭配此技能使用。
  4. 根据references/review-checklist.md进行审查。

Topics

主题

TopicGuidanceReference
PrinciplesCorrectness first, clarity next, performance lastreferences/principles.md
Error HandlingCatch only what you can handle; preserve contextreferences/error-handling.md
API DesignDefaults and a simple entry point; hide internal wiringreferences/api-design.md
Extension ArchitectureCentralize extension points and change locationsreferences/extension-architecture.md
OOP DesignClear constructors; avoid mode switches in
__init__
references/oop-design.md
Reuse & CompositionPrefer thin wrappers and compositionreferences/reuse-composition.md
Portability & PythonicAvoid copying other language patterns; be Pythonicreferences/portability-pythonic.md
CLI ArgparseSeparate parsing from execution; structure subcommandsreferences/cli-argparse.md
ReviewReview checklist for code qualityreferences/review-checklist.md
主题指南参考
原则正确性优先,其次是清晰度,最后是性能references/principles.md
错误处理仅捕获可处理的异常;保留上下文references/error-handling.md
API设计合理默认值与简单入口点;隐藏内部实现references/api-design.md
扩展架构集中管理扩展点与变更位置references/extension-architecture.md
面向对象设计清晰的构造函数;避免在
__init__
中切换模式
references/oop-design.md
复用与组合优先使用轻量包装与组合references/reuse-composition.md
可移植性与Pythonic风格避免照搬其他语言模式;遵循Pythonic风格references/portability-pythonic.md
CLI Argparse将解析与执行分离;结构化子命令references/cli-argparse.md
审查代码质量审查清单references/review-checklist.md

References

参考资料

  • Each topic file lists source URLs in its frontmatter
    urls
    .
  • 每个主题文件的前置元数据
    urls
    中列出了来源URL。