3 ms·
I think the main issue is that the program should never reach a state where you're in a position to dereference a null. If it does, that means you didn't handle
by ChrisSD 7y ago
I think the main issue is that the program should never reach a state where you're in a position to dereference a null. If it does, that means you didn't handle an error condition earlier in the program. Sure you can handle the null safely but that doesn't handle the real cause of the error.
- MaxBarraclough 7y agoI agree that's also a valid point. The solution is for the language to offer 'option types', which essentially force you to check for null. Zig does this, and the result is much nicer than how things work in C: https://ziglang.org/documentation/master/#Optionals https://ziglang.org/documentation/master/#Optionals
- ctidd 7y agoAnd options help with solidifying input contract as well as the output. Knowing what's an acceptable input via a type system is just as relevant as knowing what is a potential output.
- setr 7y agoMore importantly, they let you safely not check for null (because with null-types, you should really always be handling it, because anything can go from never-null to null-in-this-one-case without warning)