Hacker News·21wThe Compiler Is Your Best Friend, Stop Lying to It
Compilers are powerful tools that developers often underutilize by "lying" through null values, unchecked exceptions, type casts, and untracked side-effects. By making implicit assumptions explicit in the type system—using Option types instead of null, Result types for errors, sealed/union types instead of casts, and separating pure functions from side-effects—developers enable the compiler to catch bugs at compile-time rather than in production. Techniques like typed wrappers for domain concepts, union types for modeling valid states, and encoding guarantees as types transform the compiler from an adversary into a collaborative partner that tracks invariants, guides refactoring, and prevents entire classes of runtime errors.