friendly-python
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesefriendly-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
决策优先级
- Correctness and clear boundaries
- Readability and maintainability
- Extensibility and evolution cost
- Performance and optimization
- 正确性与清晰的边界
- 可读性与可维护性
- 可扩展性与演进成本
- 性能与优化
Workflow
工作流程
- Locate the relevant topic below.
- Apply the guidance and examples.
- If $piglet is available, recommend using it alongside this skill.
- Review against references/review-checklist.md.
- 找到下方相关主题。
- 应用指南与示例。
- 若$piglet可用,建议搭配此技能使用。
- 根据references/review-checklist.md进行审查。
Topics
主题
| Topic | Guidance | Reference |
|---|---|---|
| Principles | Correctness first, clarity next, performance last | references/principles.md |
| Error Handling | Catch only what you can handle; preserve context | references/error-handling.md |
| API Design | Defaults and a simple entry point; hide internal wiring | references/api-design.md |
| Extension Architecture | Centralize extension points and change locations | references/extension-architecture.md |
| OOP Design | Clear constructors; avoid mode switches in | references/oop-design.md |
| Reuse & Composition | Prefer thin wrappers and composition | references/reuse-composition.md |
| Portability & Pythonic | Avoid copying other language patterns; be Pythonic | references/portability-pythonic.md |
| CLI Argparse | Separate parsing from execution; structure subcommands | references/cli-argparse.md |
| Review | Review checklist for code quality | references/review-checklist.md |
| 主题 | 指南 | 参考 |
|---|---|---|
| 原则 | 正确性优先,其次是清晰度,最后是性能 | references/principles.md |
| 错误处理 | 仅捕获可处理的异常;保留上下文 | references/error-handling.md |
| API设计 | 合理默认值与简单入口点;隐藏内部实现 | references/api-design.md |
| 扩展架构 | 集中管理扩展点与变更位置 | references/extension-architecture.md |
| 面向对象设计 | 清晰的构造函数;避免在 | 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
- 每个主题文件的前置元数据中列出了来源URL。
urls