4 ms·
If you use Objective-C objects, operations on null pointers are just a no-op, so there is not such thing as chasing exceptions.
by coliveira 7mo ago
If you use Objective-C objects, operations on null pointers are just a no-op, so there is not such thing as chasing exceptions.
- zadikian 7mo agoSo you silently ignore something being null when you don't expect it to be? That sounds even worse.
- mpweiher 7mo agoIt's just that pointer?.doSomething() is the default. Le horreur!
- pjmlp 7mo agoNot really, because doSomething is not called if reference/pointer is null, whereas in Objective-C there is still a message that is sent to the NULL recipient.
- mpweiher 7mo agoNo, the messenger identifies the NULL recipient and does not send the message.
- zadikian 7mo agoThe Swift way is safer, but I don't like it much either. The ? explicitly says you want to ignore null, so that's fine. The problem is there's no convenient way to throw exception if null, so you're encouraged to overuse ?, as I think you alluded to. (! will crash the entire program instead.) Swift error handling is overall pretty complex too. Ironically the JS or Py error handling is actually the safest for high-level code. Exceptions are easy to work with and hard to ignore by accident. Very few ways to crash entirely. And Rust's errors are good for systems code.