Review a Function for Hidden Side Effects
Added 2026-11-02
It reads like a pure function but mutates state or fires requests.
Here is a function or method. Do: 1) mark every side effect — state writes, network calls, file writes, reads of global config, parameter mutation; 2) separate expected-by-caller from hidden ones; 3) point out which becomes a problem under concurrency or retries; 4) propose a split: pure computation versus side effect, and what it touches; 5) warn me where tests are most likely to become flaky because of side effects. Do not rewrite the whole function.
Site original
Chinese original
How to use
隐藏副作用是并发问题的常见源头。
Try tweaking it
- Have it restate requirements and constraints before writing code.
- Ask for the smallest change plus a rollback path, not a full-file rewrite.
What you should get
- A minimal, runnable change with copy-ready code
- Impact list: which files and call sites must follow
Common mistakes
- Asking it to touch ten files at once, then losing track of what broke what.
- Pasting only the error, with no code or version, and getting an unfixable answer.
How to check the output
- The change runs, can be rolled back, and touches nothing unrelated.
- Edge cases (empty, oversized, concurrent) are covered or explained.
Where it works
- Good for: having it restate requirements and constraints, then propose the smallest runnable change.
- Watch out: include versions and a minimal reproduction with the error, or the fix may look plausible but not fit.