Assert(): A Modern How To
- Programming
- Developer Tools
- Software Engineering
The post is a how-to for modern assertions and pushes a broader role for `assert` than the old “debug only” view. It frames assertions as a way to protect correctness, safety, development, and documentation, with production use on the table. The pushback is that this collapses several different tools into one word. Most people landed on a sharper definition: assertions are for internal invariants that should be impossible to violate during valid execution, while invalid user input, library misuse, and expected system-call failures need ordinary error handling, exceptions, or explicit contracts.
Treat `assert` as a check for impossible internal states, not as a general-purpose error handler. If your code needs to survive bad inputs or external failures, model invariants in types where you can, use normal runtime checks where you must, and make sure any assertion failure yields actionable crash data or a supervised restart path.
-
fiberfs.io
- Discuss on HN