HN
Zero-Cost POSIX Compliance: Encoding the Socket State Machine in Lean's Types
The best runtime check is the one that never runs.
The POSIX socket API is a state machine. A socket must be created, then bound, then set to listen, before it can accept connections. Calling operations in the wrong order — send on an unbound socket, accept before listen , close twice — is undefined behaviour in C.
Every production socket library deals with this in one of three ways:
Runtime checks — assert the state at every call, throw on violation (Python, Java, Go).
Documentation — trust the programmer to read the man page (C, Rust).
Ignore it — let the OS return EBADF and hope someone checks the return code.