Glean 拾遗
Recent picks

1pick · chronological

09-15

Write code that is easy to delete, not easy to extend.

The thesis: treat lines of code as lines spent, not lines produced. Every line carries a maintenance cost, and abstractions built for reuse bind callers to both the intended and unintended behaviour of an implementation, making later change more expensive. The goal should be disposable code, not reusable or extensible code. The author walks through tactics: don't write code at all; copy-paste a few times before extracting a function; keep stateless, application-agnostic helpers in a util directory with one utility per file; accept boilerplate so static library code stays away from fast-changing business logic; layer policy over protocol the way requests wraps urllib3; let one big ball of mud hold things together; split modules by what they don't share rather than by shared functionality; use uniform interfaces, HTTP caches/CDNs and feature flags as replaceable seams; handle errors at the outer edges (end-to-end principle), as Erlang's supervision trees do by restarting instead of recovering in place. Aimed at engineers maintaining long-lived codebases.

programmingisterrible.com · 20 min · API Design · Code · Essay