<div dir="ltr">precondition() is enabled for release builds.<br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 7, 2015 at 5:24 PM, David Hart via swift-users <span dir="ltr">&lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>You enable assertions for release builds then? Remember, I&#39;m talking specifically about library code: the same way that calling NSArray&#39;s objectAtIndex throws an exception (if my memory serves well) for out of bounds indices. At least, NSAssert in Objective-C throws exceptions and is catchable.</div><div><div class="h5"><div><br>On 08 Dec 2015, at 01:43, Jens Alfke via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><br><div><blockquote type="cite"><div>On Dec 7, 2015, at 11:39 AM, Jan Neumüller via swift-users &lt;<a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a>&gt; wrote:</div><br><div><div style="font-family:Alegreya-Regular;font-size:15px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">I fail to see any overhead here. Its the absolute minimum to get checked values. Anything less is not checking.</div></div></blockquote></div><br><div>There’s no overhead if the function already ‘throws’ / returns errors. But not all functions do that (and some functions _cannot_ do that, like operators.) If a function has to be upgraded to return an error, that _is_ extra overhead, mostly on the caller’s side. (And, as previously noted, this may complicate the programmer’s life too, because now they may have to either propagate ‘throws’ to the caller or add a ‘catch’ handler.)</div><div><br></div><div>Anyway, the programming conventions have been clear for a very long time: assertions should be used for programmer errors (like invalid parameters) while returned errors should be used for legitimate runtime error situations (like file-not-found). This predates Swift and even predates Mac OS X*; I think it goes back to OpenStep in the mid-‘90s.</div><div><br></div><div>—Jens</div><div><br></div><div>* NSError itself isn’t that old, but before that the APIs still returned nil or false for runtime errors.</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43hXwizS3O2z60WweqomIrdgZk-2BoSk5AzMgN3t5TzBUTmL9GpD90-2FZDI0TYakEdmYpO8lJLeGlRycaSEjDyPUB0SJqmj7eRuuDbWf21LqO98Vpvr6kwqeIf9Pqf5fGEVj74Ka2fRcXYdcnz1yA2itG4wzcHZrwXMxU8XG-2B58-2BYZPU5GdC0JdQJY0wT5ozp-2F2Ox68v2Q806tunm3zNbSiU0Ro-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">

</div></blockquote></div></div><blockquote type="cite"><div><span>_______________________________________________</span><span class=""><br><span>swift-users mailing list</span><br><span><a href="mailto:swift-users@swift.org" target="_blank">swift-users@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-users" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a></span><br></span></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=HvbB2rNqe6WERAH1f5iSygoap13wP4MPscYBJZE6r41OyPCvO9AXnYbOKbtJ-2FFS0JLEDD3FM1Pi98yXV-2FRk2bcvmA96LIv-2FC2nN8M0nZafOhw-2FvkRH8ROYVGGj2tbDGymYYQfrVsxagDMLLluJb3JeQAcQvJk5M-2FkWdroA1JqI8XC-2FLeyHS5xsF5lmiunhoT5CaVyHTX28ZqphoRyFGL6FRyagWOHu-2FP-2BLfFcK9JNk0-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-users mailing list<br>
<a href="mailto:swift-users@swift.org">swift-users@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br>(j){printf(&quot;%d\n&quot;,i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" target="_blank">gribozavr@gmail.com</a>&gt;*/</div>
</div></div>