2 ms·
The interesting question is not what you do once a catastrophe has happened (program has reached invalid state) but how to avoid it in the first place. Excepti
by tempodox 7y ago
The interesting question is not what you do once a catastrophe has happened (program has reached invalid state) but how to avoid it in the first place. Exceptions are better than undefined behavior in coping with the former, but they still don't help you with the latter. The idea to “make invalid states unrepresentable” would give you an actual shot at this.
- MaxBarraclough 7y ago> Exceptions are better than undefined behavior in coping with the former, but they still don't help you with the latter That's not right. Exceptions are thrown reliably and are always 'noisy'. Undefined behaviour may go completely unnoticed for a long time. Code that wrongly throws exceptions tends to get fixed. I've seen undefined behaviour in code samples in respected technical books. The code happened to work fine when using the MSVC C++ compiler and x84/AMD64 targets, and will probably continue to do so. > The idea to “make invalid states unrepresentable” would give you an actual shot at this. That's a pretty good summary of what type-systems research is aiming for. Are you following 'typestates' in Rust? I think you might enjoy this article, if you've not read it already: https://yoric.github.io/post/rust-typestate/ https://yoric.github.io/post/rust-typestate/