Weekly Review — Month 1 · Week 3 (Days 015–021)¶
📅 The Week in One Line¶
Gave types behavior with methods, decoupled code with implicitly-satisfied interfaces, and learned the full Go error toolkit — wrapping, sentinel/custom errors, Is/As/Join, and panic/recover.
✅ What I Completed¶
- Day 015 — Methods & receivers (value vs pointer)
- Day 016 — Interfaces & implicit satisfaction
- Day 017 — Type assertions & type switches
- Day 018 — Errors as values & wrapping (
%w) - Day 019 — Custom & sentinel errors;
errors.Is/As/Join - Day 020 —
panic,recover& when to use them - Day 021 — Review & closed-book recall
- Runnable examples:
methods,interfaces,errors,panic-recover - Exercises solved: 3 (shapes, counter, validate) — all with table-driven tests
💡 Lessons Learned¶
- Value vs pointer receiver is one rule: value = copy (read-only), pointer = original (mutates). Keep a type's receivers consistent.
- Interface satisfaction is implicit and based on method sets, which is why a
Tvalue can fail to satisfy an interface implemented on*T. - The nil-interface trap is real: a typed nil pointer stored in an
erroris non-nil. Return literalnilfor success. %wkeeps the error chain inspectable;%vflattens and breaks it. Compare witherrors.Is, never==, once wrapping is involved.errors.Asextracts typed errors;errors.Join(Go 1.20+) bundles many. Give custom error types anUnwrap()so the chain stays walkable.- Panic is for programmer bugs/invariants (
MustCompile), not expected failures.recoveronly works inside a deferred function.
💪 Strengths (what clicked)¶
- Methods and small interfaces ("accept interfaces, return structs") felt natural.
- Building and reading error chains with
%w+errors.Is/As.
🧩 Weaknesses (what's still fuzzy)¶
- Reflex to reach for
errors.Is/Asinstead of==under time pressure. - Spotting the nil-interface trap before it bites.
- Addressability rules for auto-
&on pointer-method calls.
🔁 Spaced-Repetition Re-quiz (topics from earlier weeks)¶
- Q: (Wk1) What does
deferevaluate eagerly vs run lazily?A
Arguments are evaluated when thedeferstatement runs; the call executes LIFO at function return. - Q: (Wk2) What happens to a slice's backing array when
appendexceedscap?A
A new, larger backing array is allocated and elements are copied; the old aliasing is broken. Withincap, append mutates the shared backing array. - Q: (Wk3)
errors.Isvserrors.As?A
Ischecks for a specific sentinel value anywhere in the chain;Asfinds and extracts an error of a given type so you can read its fields. - Q: (Wk3) Why use a pointer receiver?
A
To mutate the receiver, to avoid copying a large struct, or for consistency when other methods need a pointer.
🎯 Action Items¶
- Add a flashcard pair: "
==sentinel → useerrors.Is" and "typed nil → nil-interface trap". - Re-implement the
validateexercise from scratch using onlyerrors.Join. - Skim
io.Reader/io.Writersource to see small interfaces in the wild before Week 4.
🚀 Next Week Goals¶
- Generics (type parameters, constraints) and deeper
testing(subtests, fuzzing basics). - Apply this week's interfaces + errors in the first real mini-project boundary.
📊 Metrics¶
| Hours | Days hit | Exercises | Commits | Avg confidence |
|---|---|---|---|---|
| 9 | 7/7 | 3 | 7 | 3.⅗ |
Suggested commit: docs(journal): week 3 review