Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you use Objective-C objects, operations on null pointers are just a no-op, so there is not such thing as chasing exceptions.
 help



So you silently ignore something being null when you don't expect it to be? That sounds even worse.

It's just that

    pointer?.doSomething()
is the default. Le horreur!

The 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.


Not 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.

No, the messenger identifies the NULL recipient and does not send the message.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: