DHI / DHI/python-package-development

Clarify benefits of factory methods in Module 2

未关闭
#31 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Jupyter Notebook
星标
8
派生
1
平均合并
4 分钟
30 天内合并 PR
1

描述

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.

贡献指南

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

调研方向

Start with the static methods section in Module 2 and review its current explanation of factory methods. Add the requested terminology, rationale, and datetime and polars examples; done means the section explains when and why to use the pattern and includes the listed examples.

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

评估

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

把新 issue 发到你的邮箱

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