Skip to content

Commit 5b169ab

Browse files
committed
Fill journey gap examples
1 parent 764288f commit 5b169ab

57 files changed

Lines changed: 6059 additions & 495 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Production: <https://www.pythonbyexample.dev> (`workers.dev` remains enabled as
66

77
## Features
88

9-
- 70 curated Python 3.13 examples in learning order
9+
- 104 curated Python 3.13 examples in learning order
1010
- Literate source/output cells for each example walkthrough
1111
- Editable complete examples powered by CodeMirror
1212
- Read-only syntax highlighting powered by Shiki

docs/example-quality-rubric.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ Score each example on a 10 point scale:
1313
7. **Source/result pairing (0-1.0)** — each important source fragment has nearby output that proves the semantic point, not merely that the code ran.
1414
8. **Concept decomposition (0-1.0)** — the example breaks the concept into meaningful parts instead of presenting one compressed trick.
1515
9. **Progressive walkthrough (0-0.75)** — each cell introduces one new idea, and the sequence builds toward the complete concept. Single-cell examples are acceptable only for intentionally atomic concepts.
16-
10. **Representative coverage (0-0.75)** — the code covers the forms promised by the title, summary, and prose, and the catalog has an explicit home for every common Python syntax form. Do not claim lists, dictionaries, and sets while showing only two of them; do not let syntax such as `break`, `continue`, `assert`, `nonlocal`, `yield from`, or `async for` exist only as untested assumptions.
16+
10. **Representative coverage (0-0.75)** — the code covers the forms promised by the title, summary, and prose, and the catalog has an explicit home for every common Python syntax form. Do not claim lists, dictionaries, and sets while showing only two of them; do not let syntax such as `break`, `continue`, `assert`, `nonlocal`, `yield from`, `async for`, or `:=` exist only as untested assumptions.
1717
11. **Practical usefulness (0-1.0)** — names, data, and outputs resemble simplified real code rather than toy placeholders; the example gives the feature a reason to exist.
18+
12. **Editorial progression (0-1.0)** — broad examples move through a deliberate sequence: motivation, smallest concrete form, model/protocol, common operations, boundary or edge case, and neighboring concepts. The page should feel like a guided exposition rather than a sample tray.
1819

1920
Topic-specific gates:
2021

2122
- **Text and strings** — examples must distinguish text from bytes, explain Unicode/code-point behavior when relevant, and show the boundary where encoding such as UTF-8 appears. A string page that only demonstrates ASCII operations is incomplete. When using non-English text to show that code points and bytes differ, include an English/ASCII baseline with the same kind of phrase so the contrast is visible rather than implied.
23+
- **Broad surface tours** — if a title names a broad surface area (`Testing`, `Packages`, `Regular Expressions`, `Type Hints`, `Async Await`, `Special Methods`, `Operators`, `Literals`), the page must either cover the reader's reasonable expectations or clearly frame itself as a first pass and link to focused neighbors. A broad title with one narrow demonstration is a scope bug, not just a content gap.
24+
- **Reduce without distorting** — small examples are good only when the necessary boundary, contrast, or edge case remains visible. If compression removes the part that makes the concept understandable, split the example or add another cell.
25+
- **Map-or-split rule** — broad pages must either be surface maps with explicit categories and `See also` links, or be split into narrower pages. Do not ship a broad page that merely samples unrelated forms.
26+
- **Runtime-boundary examples** — when standard Python code cannot run in Dynamic Workers, teach the standard form first, state the runtime constraint once, and avoid repeated apology or caveat-heavy prose.
2227

2328
Release gates outside the score:
2429

@@ -58,6 +63,13 @@ Flag these during review even when the code is correct:
5863
- The page does not connect the feature to a nearby alternative, such as `while` vs `for`, slice vs index, tuple vs list, text `str` vs binary `bytes`, or f-string expression vs display formatting.
5964
- An iteration example uses a lazy object but does not show when values are consumed.
6065
- An iteration example blurs eager containers with one-pass streams.
66+
- A broad title hides a narrow example: the page sounds like a tour of a surface area but demonstrates only one isolated technique.
67+
- A syntax form has a focused example but is missing from a natural umbrella page where learners would expect to see it.
68+
- The journey order follows implementation/catalog history instead of prerequisites: conditionals before booleans, closures before scope, networking before bytes, or process boundaries before environment boundaries.
69+
- Runtime constraints are repeated in the intro, code block, notes, and runner area until the limitation overwhelms the Python lesson.
70+
- The page has no editorial progression: examples are technically related but ordered like a checklist rather than a learning path.
71+
- The page reduces so aggressively that a necessary edge case or contrast disappears.
72+
- `See also` links behave like tags instead of prerequisite, neighbor, or next-depth graph edges.
6173

6274
## Strengthening checklist
6375

@@ -74,3 +86,11 @@ Before publishing or substantially editing an example, ask:
7486
9. Does the data shape explain why this feature exists?
7587
10. What syntax form would disappear from the catalog if this page were removed, and is that covered somewhere else?
7688
11. For text examples, does the page make Unicode and encoding boundaries visible instead of assuming ASCII-only strings? If non-English text is used, is it compared with an English/ASCII baseline?
89+
12. If the title names a broad surface area, what would a learner reasonably expect to see, and is that expectation met or explicitly scoped down?
90+
13. Is any important syntax form covered only in a focused page even though an umbrella page should point to it?
91+
14. Does the journey sequence respect prerequisites rather than merely mirroring catalog order?
92+
15. If the page mentions a runtime limitation, is the constraint stated once without becoming the main story?
93+
16. Does the page reduce the concept without distorting it, or did compression remove an essential boundary?
94+
17. For broad pages, is this a map with categories and links, or should it be split?
95+
18. Do edge cases appear close enough to the main idea that readers understand the boundary?
96+
19. Do `See also` links express prerequisite, neighbor, or next-depth relationships rather than tags?

docs/lessons-learned.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ This document records project lessons that should guide future changes to Python
3737
- When storing examples as Markdown, keep the full editable program in `:::program` and teaching fragments in separate `:::cell` blocks. Do not concatenate cells to recreate the editor source.
3838
- Fine-grained cells can restate definitions to stay executable. This is better than collapsing class, property, recursion, match, or type-hint examples into one large cell.
3939
- Preserve a frozen golden catalog while migrating source formats. Full stdout parity is not enough; rendered teaching-cell structure must also match.
40+
- Beware broad-surface titles that quietly teach only one narrow slice. Pages named `Testing`, `Packages`, `Regular Expressions`, `Type Hints`, `Async Await`, or `Special Methods` must either cover the forms a reader reasonably expects or explicitly frame themselves as a first pass and link to focused neighbors.
41+
- Do not let an important syntax form live only in a separate page if another page title strongly implies it. An umbrella `Operators` page should at least point to and lightly show `:=`, even though `Assignment Expressions` remains the focused lesson.
42+
- Journey order should follow prerequisite thinking, not catalog order. Put booleans before truthiness and conditionals, scope before closures, bytes before networking, and environment boundaries before subprocess/thread boundaries.
43+
- Runtime-boundary caveats should not become the hero. For Dynamic Worker limitations, teach normal Python first and state the constraint once in the marked boundary cell.
44+
- Algebrica's useful editorial principle is “reduce without distorting.” Python examples should be compact, but not so compressed that the concept loses its necessary contrast, edge case, or progression.
45+
- Broad examples need a visible learning arc. If a page reads like a tray of samples, either add a map-like progression or split it into narrower examples.
46+
- Keep teaching artifacts inspectable. Markdown sources, editable programs, teaching cells, expected output, and diagrams/screenshots should be clean enough to serve as public educational material, not just implementation input.
47+
48+
### Broad-surface audit notes
49+
50+
- `Operators and Literals`: fixed by splitting it into `Operators` and `Literals`, then adding `:=` surface coverage and a `See also` link to `Assignment Expressions` from `Operators`.
51+
- `Special Methods`: fixed by keeping the entry page small and adding focused data-model pages for truth/size, containers, callables, operators, and attribute access.
52+
- `Testing`: fixed by replacing boilerplate with arrange/assert/run structure and explicit scoping to the smallest `unittest` loop.
53+
- `Packages`: fixed by splitting package-as-module, dotted imports, and dynamic import into separate cells.
54+
- `Regular Expressions`: fixed by separating repeated extraction, first-match groups, and the string-method alternative.
55+
- `Async Await` and `Type Hints`: acceptable for now because both state their boundaries and are supported by focused neighboring examples/journeys.
4056

4157
## Layout and mobile
4258

docs/research-algebrica.md

Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
# Research note: Algebrica
2+
3+
Sources:
4+
5+
- <https://github.com/antoniolupetti/algebrica>
6+
- <https://algebrica.org>
7+
8+
Algebrica is a free, ad-free mathematics knowledge base whose repository publishes source Markdown and editable SVG diagrams. Its README describes an editorial goal that is directly relevant to Python By Example: **reduce without distorting**. Pages are written from multiple university-level sources, reconciled into a coherent exposition, and revised as adjacent pages expose gaps or inconsistencies.
9+
10+
## What we can learn
11+
12+
### 1. Strong pages have a deliberate progression
13+
14+
Algebrica pages do not read like disconnected fact lists. A page such as `definite-integrals` moves through a clear learning arc:
15+
16+
```text
17+
geometric intuition
18+
→ approximation
19+
→ formal definition
20+
→ computation rule
21+
→ properties
22+
→ worked examples
23+
→ edge cases
24+
→ links to deeper pages
25+
```
26+
27+
For Python By Example, broad examples should have a comparable editorial progression:
28+
29+
```text
30+
why this exists
31+
→ smallest concrete form
32+
→ runtime/protocol model
33+
→ common operations
34+
→ boundary or edge case
35+
→ worked output
36+
→ neighboring concepts
37+
```
38+
39+
The former `Operators and Literals` page failed this test: it sampled useful syntax but did not provide a coherent map. Splitting it into `Operators` and `Literals` improved the title-to-content contract.
40+
41+
### 2. Reduce without distorting
42+
43+
Small examples are valuable only when they preserve the concept. If an example compresses too much into one cell, it can become technically correct but educationally shallow.
44+
45+
Example risk:
46+
47+
```text
48+
Bytes and Bytearray: encode, length contrast, decode, and mutation all in one cell.
49+
```
50+
51+
Better progression:
52+
53+
```text
54+
text → UTF-8 bytes
55+
bytes → text
56+
bytes indexing / immutability
57+
bytearray mutation
58+
```
59+
60+
### 3. Broad concepts need maps, not sample trays
61+
62+
Algebrica handles broad topics by organizing subtopics. It does not merely sample a few facts and hope the title carries the rest.
63+
64+
For us, broad pages should either:
65+
66+
1. be scoped explicitly as a first pass / surface map, with links to focused neighbors; or
67+
2. be split into narrower examples.
68+
69+
Examples that need this discipline include `Testing`, `Modules`, `Packages`, `Type Hints`, `Operators`, `Literals`, `Bytes and Bytearray`, and the type-system cluster.
70+
71+
### 4. Teaching artifacts should be inspectable
72+
73+
Algebrica releases source Markdown and editable SVGs. The lesson is not that Python By Example needs more diagrams; it is that core teaching artifacts should be inspectable, reusable, and versioned.
74+
75+
For Python By Example, the inspectable artifacts are:
76+
77+
- Markdown examples
78+
- `:::program` complete runner source
79+
- `:::cell` teaching fragments
80+
- expected output
81+
- official docs links
82+
- generated embedded source
83+
- tests and golden parity fixtures
84+
- rubric and lessons learned docs
85+
86+
### 5. Cross-links should express prerequisites and next depth
87+
88+
Algebrica links to prerequisite concepts and deeper topics as part of the explanation, not as decorative tags.
89+
90+
For us, `See also` links should keep behaving like a conceptual graph:
91+
92+
```text
93+
operators → assignment-expressions, operator-overloading
94+
literals → strings, bytes-and-bytearray, dicts
95+
bytes-and-bytearray → strings, networking
96+
type-aliases → type-hints, newtype
97+
```
98+
99+
### 6. Edge cases belong near the main idea
100+
101+
The definite-integrals page introduces positive/negative area and improper integrals after the main computation story. Edge cases are part of the concept, not trivia hidden at the end.
102+
103+
For Python examples, this suggests adding visible boundary cells for common misunderstandings:
104+
105+
- `json`: non-JSON Python objects or decode errors
106+
- `testing`: failing-test output or what the result object records
107+
- `bytes-and-bytearray`: indexing bytes yields integers; `bytes` is immutable
108+
- `type-hints`: hints inform tools but do not enforce runtime behavior
109+
- `operators`: precedence and parentheses
110+
111+
### 7. Process transparency builds trust
112+
113+
Algebrica documents editorial process, source reuse, licensing, and revision. Python By Example should continue to surface its own trust signals:
114+
115+
- official Python docs links
116+
- deterministic expected output
117+
- verification scripts
118+
- CI
119+
- cache/versioning checks
120+
- public Markdown source
121+
- quality rubric
122+
- lessons learned
123+
124+
## Rubric changes implied
125+
126+
Add or strengthen these rubric checks:
127+
128+
1. **Editorial progression** — broad examples need a visible sequence, not a grab bag.
129+
2. **Scope contract** — title, summary, and first paragraphs must match the breadth of the code.
130+
3. **Reduction without distortion** — examples may be small, but not at the cost of removing a necessary boundary, contrast, or edge case.
131+
4. **Map-or-split rule** — broad pages must either become surface maps with links to focused neighbors or be split into narrower pages.
132+
5. **Edge case placement** — common edge cases should appear in cells or concrete notes near the main idea.
133+
6. **Inspectable artifact quality** — Markdown source should remain clean enough to serve as public educational material, not merely runtime input.
134+
7. **Conceptual links as graph edges**`See also` should mark prerequisite/neighbor/next-depth relationships.
135+
136+
## Known improvement queue
137+
138+
### Improve existing examples
139+
140+
High priority:
141+
142+
- `bytes-and-bytearray` — split one compressed cell into encode/decode/immutability-mutation cells.
143+
- `type-aliases` — replace generic prose; contrast `type` aliases, assignment-style aliases, and `NewType`.
144+
- `operators` — monitor for sample-tray drift; add precedence/parentheses if readers need it.
145+
- `literals` — keep as source-syntax map; ensure it does not pretend to teach every value type deeply.
146+
147+
Type-system cluster:
148+
149+
- `runtime-type-checks`
150+
- `union-and-optional-types`
151+
- `typed-dicts`
152+
- `callable-types`
153+
- `generics-and-typevar`
154+
- `casts-and-any`
155+
- `newtype`
156+
157+
Each should gain at least one contrast cell showing static-tool meaning versus runtime behavior or misuse boundary.
158+
159+
Medium priority:
160+
161+
- `numbers` — link complex literal syntax to `literals`; consider future `decimal-and-fractions`.
162+
- `modules` — scope as imports/namespaces; consider entry-point/import-system follow-ups.
163+
- `packages` — optionally add an illustrative package tree as `:::unsupported` or prose.
164+
- `regular-expressions` — keep scoped as first pass; consider flags/substitution only as focused follow-ups.
165+
- `testing` — consider failing-test output or fixtures if deterministic output stays readable.
166+
- `json` — consider indentation, decode errors, or non-JSON objects as a boundary cell.
167+
- `decorators` — consider `functools.wraps` metadata preservation.
168+
- `context-managers` — consider a small `__enter__` / `__exit__` protocol cell or stronger link to data model examples.
169+
- `exceptions` — consider `else` / `finally` cleanup if reliability coverage needs it.
170+
171+
### Create new examples
172+
173+
Potential focused pages:
174+
175+
- `decimal-and-fractions`
176+
- `module-entry-points`
177+
- `import-system`
178+
- `regex-substitution`
179+
- `regex-flags`
180+
- `test-fixtures`
181+
- `pytest-style-tests`
182+
- `json-errors`
183+
- `operator-precedence`
184+
- `exception-cleanup`
185+
186+
### Journey changes to consider
187+
188+
- **Runtime** — ensure `Literals` and `Operators` remain placed by prerequisite logic, not catalog convenience.
189+
- **Control Flow** — keep `Operators` before `Conditionals` only while the page covers comparisons and boolean expressions.
190+
- **Types** — add contrast cells before adding more type pages; avoid a long list of shallow type examples.
191+
- **Reliability** — consider whether `Testing`, `Logging`, `Exceptions`, and cleanup examples form a stronger progression if `exception-cleanup` or `test-fixtures` is added.
192+
- **Interfaces** — keep the data-model sequence coherent: `Special Methods` → focused protocol pages → `Descriptors``Metaclasses`.
193+
194+
### Remove or avoid
195+
196+
- Avoid restoring a combined `Operators and Literals` page.
197+
- Avoid broad catch-all pages that merely list syntax without a learning progression.
198+
- Avoid adding new examples to journeys unless they strengthen the story rather than lengthen the index.

0 commit comments

Comments
 (0)