4 ms·
It's just that pointer?.doSomething() is the default. Le horreur!
by mpweiher 8mo ago
It's just that
pointer?.doSomething()
is the default. Le horreur!
- pjmlp 8mo 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 8mo agoNo, the messenger identifies the NULL recipient and does not send the message.
- zadikian 8mo 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.