<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">In that case, we really need a way to unit-test assertions, because unit-testing illegal parameters in a library seems critical.</div><div class="">David.</div><br class=""><div><blockquote type="cite" class=""><div class="">On 07 Dec 2015, at 06:33, Jens Alfke <<a href="mailto:jens@mooseyard.com" class="">jens@mooseyard.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 6, 2015, at 12:49 PM, David Hart via swift-users <<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">When writing library code, what method of parameter validation would be suggested?</div></div></blockquote><br class=""></div><div class="">Definitely assert. Assert is for illegal calls, i.e. programmer errors, while errors (throw) are for valid runtime error conditions.</div><br class=""><div class=""><blockquote type="cite" class=""><div class="" style="font-family: Alegreya-Regular;"><u class="">Cons</u></div><div class="" style="font-family: Alegreya-Regular;">* Disabled in release</div></blockquote><div class=""><br class=""></div><div class="">I believe there is a compiler flag to control this, if you want them enabled in the release.</div><br class=""><blockquote type="cite" class=""><div class="" style="font-family: Alegreya-Regular;">* Not unit-testable</div></blockquote></div><div class=""><div class="" style="font-family: Alegreya-Regular;"><br class=""></div></div><div class="" style="font-family: Alegreya-Regular;">Well, you can’t create tests for rejection of illegal parameters. Which doesn’t seem like a huge loss to me. It would be nice to be able to do this, though. Maybe through some mechanism for catching / recovering from the otherwise-fatal exception triggered by an assert failure?</div><div class="" style="font-family: Alegreya-Regular;"><br class=""></div><div class="" style="font-family: Alegreya-Regular;">—Jens</div></div></div></blockquote></div><br class=""></body></html>