Clarify benefits of factory methods in Module 2

未关闭
#31 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
半天
新手友好度
55/100
Issue 类型
文档
描述清晰度
描述清楚
活跃度
停滞
技术栈
jupyter-notebook, python
领域
documentation

调研方向

从 Module 2 中的 static methods 部分开始,审查其中对 factory methods 的现有说明。添加所要求的术语、理由以及 datetime 和 polars 示例;完成的标准是该部分说明何时以及为何使用此模式,并包含列出的示例。

由索引模型根据 Issue 内容生成。

描述

The static methods section in Module 2 shows how to create factory methods but could better explain when and why to use them.

Current state

The notes mention it's "less cumbersome" to create instances, but the pedagogical value could be stronger.

Suggested improvements

  1. Name the pattern - Use the term "factory method" or "alternative constructor" so students can recognize and search for it

  2. Explain the "why" - Python doesn't support multiple __init__ signatures, so factory methods provide multiple construction paths with semantic clarity

  3. Add stdlib examples from datetime:

    • datetime.fromtimestamp()
    • datetime.fromisoformat()
    • date.fromordinal()
  4. Add examples from polars:

    • pl.read_csv(), pl.read_parquet(), pl.read_json() (module-level factories)
    • DataFrame.to_dict()pl.from_dict() round-trip
    • pl.from_numpy(), pl.from_pandas()

These examples show the pattern is pervasive in well-designed Python APIs.

主要语言
Jupyter Notebook
星标
8
派生
1
平均合并
4 分钟
30 天内合并 PR
1

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DHI/python-package-development 的其他 Issue

查看 DHI/python-package-development 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。