<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<blockquote type="cite" style="color: #000000;">
<pre class="moz-quote-pre" wrap="">Perhaps there could be the opposite modifier, so the function cannot be called with nil. Like
<pre class="moz-quote-pre" wrap="">Interesting idea but I’d have to think about it more to know if this is a real problem I’ve ever experienced.
<p>for example, I store some interfaces in a list, and just replaced
the default list with a faster list that assumes all interfaces in
the list are non-nil. (When you know the interface is non-nil, you
can replace the automatic reference counting with a direct call to
._addref, which is faster. )<br>
<p>But then it crashed because somewhere it was used with a nil
interface. There it would have been useful to mark the new
function as only non-nil accepting, so that it is clear it cannot
be used like the old function, and the compiler have made sure
there is no call with nil<br>
Well, as far as the "optional" part goes, the benefits of it
will be fairly limited. Object variables occur in many places,
and all of them can have the nil value, and the compiler has no
idea if you did the check.
You pick a tiny subset of those cases, and attempt to add
protection to it. Given the gain (or rather absence of it,
according to the microscopic size of that subset) the effort
(and chance of false positives) is not worth it.
<p>You would need to have optional or non-nil markers at every
variable, before it becomes really useful.</p>