> On Dec 6, 2015, at 12:49 PM, David Hart via swift-users 
> <swift-users@swift.org> wrote:
> 
> When writing library code, what method of parameter validation would be 
> suggested?

Definitely assert. Assert is for illegal calls, i.e. programmer errors, while 
errors (throw) are for valid runtime error conditions.

> Cons
> * Disabled in release

I believe there is a compiler flag to control this, if you want them enabled in 
the release.

> * Not unit-testable


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?

—Jens
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

Reply via email to