3 ms·
Asserts are a goto of ensuring correctness. Versatile, powerful, and incredibly easy to misuse. Whatever correctness goal you're trying to achieve, there are s
by klibertp 2mo ago
Asserts are a goto of ensuring correctness. Versatile, powerful, and incredibly easy to misuse.
Whatever correctness goal you're trying to achieve, there are safer, more ergonomic, and stronger alternatives you can reach for: type systems, contract systems, and even normal exception handling are often better. However, if you work in a domain where such tools can't be used or are not available, assert will still be there for you. It's worth knowing how to use it for that situation, but you should favor less ad hoc, more systematic features to ensure correctness in day-to-day programming.